C# WinForm MDI窗口去掉边框

1、主窗体using System.Runtime.InteropServices;

2、主窗体添加以下代码:

        private const int GWL_STYLE = -16;
        private const int GWL_EXSTYLE = -20;
        private const int WS_BORDER = 0x00800000;
        private const int WS_EX_CLIENTEDGE = 0x00000200;
        private const uint SWP_NOSIZE = 0x0001;
        private const uint SWP_NOMOVE = 0x0002;
        private const uint SWP_NOZORDER = 0x0004;
        private const uint SWP_NOACTIVATE = 0x0010;
        private const uint SWP_FRAMECHANGED = 0x0020;
        private const uint SWP_NOOWNERZORDER = 0x0200;


        // Win32 方法    
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int GetWindowLong(IntPtr hWnd, int Index);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);

        [DllImport("user32.dll", ExactSpelling = true)]
        private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
            int X, int Y, int cx, int cy, uint uFlags);

3、主窗体Load方法中添加以下代码:

            for (int i = 0; i < this.Controls.Count; i++)
            {
                var mdiClientForm = this.Controls[i] as MdiClient;
                if (mdiClientForm == null) continue;
                // 找到了mdi客户区    
                // 取得客户区的边框    
                int style = GetWindowLong(mdiClientForm.Handle, GWL_STYLE);
                int exStyle = GetWindowLong(mdiClientForm.Handle, GWL_EXSTYLE);
                style &= ~WS_BORDER;
                exStyle &= ~WS_EX_CLIENTEDGE;

                // 调用win32设定样式    
                SetWindowLong(mdiClientForm.Handle, GWL_STYLE, style);
                SetWindowLong(mdiClientForm.Handle, GWL_EXSTYLE, exStyle);

                // 更新客户区    
                SetWindowPos(mdiClientForm.Handle, IntPtr.Zero, 0, 0, 0, 0,
                    SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
                    SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
                UpdateStyles();
                break;
            }

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值