Winform下去除MDI表單邊框

來源:互聯網
上載者:User

標籤:程式   dex   ram   擷取   方法   bsp   flags   constant   orm   

做項目中間遇到了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  

 

Winform下去除MDI表單邊框

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.