如何从MDI父窗体中的MDIClient组件中删除3d边框(凹陷)?

我正在VS2010(.NET 4.0)中开发WinForms MDI应用程序,我只是讨厌MDI父表单中的3D边框。

所以关于如何去除它的任何想法(使它平坦或者没有边界)?

我知道这是一个很老的post,但我花了一些时间和痛苦来处理3D边界的东西(因为我也需要它)来自互联网上的碎片,包括:

来自codeproject.com的Jacob Slusser页面的元素(访问时间:2010年8月1日)

所以这里是:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace MDITest { public static class MDIClientSupport { [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); private const int GWL_EXSTYLE = -20; private const int WS_EX_CLIENTEDGE = 0x200; private const uint SWP_NOSIZE = 0x0001; private const uint SWP_NOMOVE = 0x0002; private const uint SWP_NOZORDER = 0x0004; private const uint SWP_NOREDRAW = 0x0008; private const uint SWP_NOACTIVATE = 0x0010; private const uint SWP_FRAMECHANGED = 0x0020; private const uint SWP_SHOWWINDOW = 0x0040; private const uint SWP_HIDEWINDOW = 0x0080; private const uint SWP_NOCOPYBITS = 0x0100; private const uint SWP_NOOWNERZORDER = 0x0200; private const uint SWP_NOSENDCHANGING = 0x0400; public static bool SetBevel(this Form form, bool show) { foreach (Control c in form.Controls) { MdiClient client = c as MdiClient; if (client != null) { int windowLong = GetWindowLong(c.Handle, GWL_EXSTYLE); if (show) { windowLong |= WS_EX_CLIENTEDGE; } else { windowLong &= ~WS_EX_CLIENTEDGE; } SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong); // Update the non-client area. SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); return true; } } return false; } } } 

在表单加载事件调用中:

 form.SetBevel(false); 

不要忘记更改名称空间并记住这是一个扩展方法,但可以将其更改为jsut在另一个类或MDI父表单中的方法调用。

如果您不想导入外部库,还会有以下作弊重新定位/调整mdi容器控件的大小。

  protected override void OnLoad(EventArgs e) { var mdiclient = this.Controls.OfType().Single(); this.SuspendLayout(); mdiclient.SuspendLayout(); var hdiff = mdiclient.Size.Width - mdiclient.ClientSize.Width; var vdiff = mdiclient.Size.Height - mdiclient.ClientSize.Height; var size = new Size(mdiclient.Width + hdiff, mdiclient.Height + vdiff); var location = new Point(mdiclient.Left - (hdiff / 2), mdiclient.Top - (vdiff / 2)); mdiclient.Dock = DockStyle.None; mdiclient.Size = size; mdiclient.Location = location; mdiclient.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; mdiclient.ResumeLayout(true); this.ResumeLayout(true); base.OnLoad(e); } 

尝试将FormBorderStyle属性更改为FixedSingle