你不能改变它。这是 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);
}