我根据我在 stackoverflow 和谷歌搜索中找到的其他帖子编写了这段代码。
我已经测试过了,它可以工作。
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", ExactSpelling = true)]
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
const int GWL_EXSTYLE = -20;
const int WS_EX_CLIENTEDGE = 0x200;
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_NOZORDER = 0x0004;
const uint SWP_NOACTIVATE = 0x0010;
const uint SWP_FRAMECHANGED = 0x0020;
const uint SWP_NOOWNERZORDER = 0x0200;
private void MdiEdgeBorderOnOff(bool off)
{
foreach(Control ctl in this.Controls)
{
if (ctl.GetType() != typeof(MdiClient)) continue;
int wnd = GetWindowLong(ctl.Handle, GWL_EXSTYLE);
if (off)
wnd &= ~WS_EX_CLIENTEDGE;
else
wnd |= WS_EX_CLIENTEDGE;
SetWindowLong(ctl.Handle, GWL_EXSTYLE, wnd);
SetWindowPos(ctl.Handle, IntPtr.Zero, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
}