【问题标题】:How to enable Visual Style of the Form in Visual Studio Designer?如何在 Visual Studio 设计器中启用窗体的视觉样式?
【发布时间】:2021-04-08 16:31:27
【问题描述】:

我使用的是 Visual Studio 2019。设计器中的表单外观看起来比运行应用程序时要旧。

是否有意如此,是否可以更改设计器中的外观?

【问题讨论】:

  • 试过但没有任何作用。
  • 设计器中托管的表单不是顶层表单,顶层窗口主题将不适用。 (它可能是 Windows API 中的错误,也可能是设计使然,但它与 Visual Studio、Windows Forms .NET 或您的主题设置没有任何关系。)
  • 为此,您可以在Developer Community 上建议一项功能。
  • @KyleWang 据我所知,这是 Windows 功能,而不是 VS 功能。例如,即使您使用 SetParent 并将记事本窗口设置为另一个记事本窗口的子窗口,您在呈现标题栏时也会看到类似的行为。在这个例子中,VS 与渲染记事本标题栏无关,它只是操作系统。

标签: .net visual-studio winforms windows-forms-designer


【解决方案1】:

你不能改变它。这是 Windows 功能(错误),而不是 VS 或 .NET 功能(错误)。

设计器中托管的表单不是顶级表单,因此顶级窗口主题将不适用于它。它可能是 Windows 中的错误,也可能是设计使然,但它与 Visual Studio、Windows Forms .NET 或您的主题设置没有任何关系。

例如,即使您使用SetParent 并将记事本窗口设置为另一个记事本窗口的子窗口,您在呈现标题栏时也会看到类似的行为。在这个例子中,VS 与渲染记事本标题栏无关,它只是操作系统:

以上示例由以下代码创建:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
    int X, int Y, int cx, int cy, int uFlags);

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
string lpszClass, string lpszWindow);

private void button1_Click(object sender, EventArgs e)
{
    var parent = Process.Start("notepad.exe");
    parent.WaitForInputIdle();

    var edit = FindWindowEx(parent.MainWindowHandle, IntPtr.Zero, "Edit", null);
    SetWindowPos(edit, IntPtr.Zero, 0, 0, 0, 0, 0x0080);

    var child = Process.Start("notepad.exe");
    child.WaitForInputIdle();
    SetParent(child.MainWindowHandle, parent.MainWindowHandle);

    SetWindowPos(child.MainWindowHandle, IntPtr.Zero, 30, 30, 300, 200, 0x0000);
}

【讨论】:

    【解决方案2】:

    我建议你使用 UI 组件,例如 GunaUI 或 DevComponent。那么你的表格会更好看。 我不知道您是否是说“设计器中的表单外观看起来比运行应用程序中的要旧” 但最好使用组件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多