C# 如何从MDI父窗体中的MDI客户端组件中删除三维边框(凹陷)?

C# 如何从MDI父窗体中的MDI客户端组件中删除三维边框(凹陷)?,c#,.net,winforms,C#,.net,Winforms,我正在VS2010(.NET 4.0)中开发WinForms MDI应用程序,我只是讨厌MDI父窗体中的3D边框 那么,有没有关于如何删除它的想法(使其平坦或完全没有边框)?尝试将FormBorderStyle属性更改为FixedSingle我知道这是一篇老文章,但我花了一些时间和精力来处理3D边框的内容(因为我也需要它)来自互联网上的片段,包括: 下面是: using System; using System.Collections.Generic; using System.Linq; u

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


那么,有没有关于如何删除它的想法(使其平坦或完全没有边框)?

尝试将FormBorderStyle属性更改为FixedSingle

我知道这是一篇老文章,但我花了一些时间和精力来处理3D边框的内容(因为我也需要它)来自互联网上的片段,包括:

下面是:

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);

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

如果您不希望导入外部库,还可以使用以下方法重新定位/调整MDI容器控件的大小

    protected override void OnLoad(EventArgs e)
    {
        var mdiclient = this.Controls.OfType<MdiClient>().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);
    }
protected override void OnLoad(事件参数e)
{
var mdiclient=this.Controls.OfType().Single();
这个.SuspendLayout();
mdiclient.SuspendLayout();
var hdiff=mdiclient.Size.Width-mdiclient.ClientSize.Width;
var vdiff=mdiclient.Size.Height-mdiclient.ClientSize.Height;
变量大小=新大小(mdiclient.Width+hdiff,mdiclient.Height+vdiff);
变量位置=新点(mdiclient.Left-(hdiff/2),mdiclient.Top-(vdiff/2));
mdiclient.Dock=DockStyle.None;
mdiclient.Size=大小;
mdiclient.Location=位置;
mdiclient.Anchor=AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
mdiclient.ResumeLayout(true);
此.resume布局(true);
基础荷载(e);
}

这是我尝试的第一件事。。。主窗体失去“大小”,3D边框仍然存在!不,你被它缠住了。MdiClient类没有BorderStyle属性,我也看不到任何明显的方法可以连接到其实例的创建中。它不再适用于Windows 10上的.NET Framework 4(可能还有更高版本)。也许是关于Aero主题,我不知道。我刚刚测试过它,它在.NET4.8上运行得很好。但是,我的系统上有一些更新挂起,所以我会在那之后再次检查。@Roni Tovi只是为了确认我之前所说的代码在Windows 10上的.NET 4.0和4.8上工作。不-它不能完全工作。它仅适用于左右和底部边界。我仍然可以看到上边框。在Windows 10 V1903;上为我工作。net 4.6.1。