protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE) { // 屏蔽傳入的消息事件 this.WindowState = FormWindowState.Minimized; return; } base.WndProc(ref m); }
protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; const int SC_MINIMIZE = 0xF020; if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE)) { //最小化到系統欄 this.Hide(); return; } base.WndProc(ref m); }
重寫 WndProc函數來同時實現無標題欄的窗體移動和禁止雙擊窗體最大化
?
protected override void WndProc(ref Message m) { const int WM_NCHITTEST = 0x84; const int HTCLIENT = 0x01; const int HTCAPTION = 0x02; const int WM_SYSCOMMAND = 0x112; const int SC_MAXMIZE = 0xF030; const int WM_NCLBUTTONDBLCLK = 0xA3; switch (m.Msg) { case 0x4e: case 0xd: case 0xe: case 0x14: base.WndProc(ref m); break; case WM_NCHITTEST://鼠標點任意位置后可以拖動窗體 this.DefWndProc(ref m); if (m.Result.ToInt32() == HTCLIENT) { m.Result = new IntPtr(HTCAPTION); return; } break; case WM_NCLBUTTONDBLCLK://禁止雙擊最大化 Console.WriteLine(this.WindowState); return; break; default: base.WndProc(ref m); break; } }
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
