zoukankan      html  css  js  c++  java
  • Winform下去除MDI窗体边框

    做项目中间遇到了MDI窗体内边框的问题,经过苦苦寻找,最终得到了解决方案

    在Main窗体中调用API

      // Win32 Constants    
            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);


    获取到API后在Form_Load事件中加入如下代码
      //获取mdi客户区    
                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;
                }

    重新运行程序,OK  

  • 相关阅读:
    发布MeteoInfo 1.2.4
    发布MeteoInfo 1.2.3
    FY2E HDF格式数据处理绘图
    格点插值为站点数据批量处理
    Linux安装make无法使用
    sql语句优化
    在OSX狮子(Lion)上安装MYSQL(Install MySQL on Mac OSX)
    JetBrains IntelliJ IDEA for Mac 15.0 破解版 – Mac 上强大的 Java 集成开发工具
    Spring-data-redis: 分布式队列
    Spring Boot使用Redis进行消息的发布订阅
  • 原文地址:https://www.cnblogs.com/bryantzx/p/7845300.html
Copyright © 2011-2022 走看看