Minimize Winform interception, maximize, close events [arrangement], and minimize winform
1 const int WM_SYSCOMMAND = 0x112; 2 // form close Message 3 const int SC _CLOSE = 0xf060; 4 // form minimize message 5 const int SC _MINIMIZE = 0xf020; 6 // form maximize Message 7 const int SC _MAXIMIZE = 0xf030; 8 // form restore Message 9 const int SC _NOMAL = 0xf120; 10 // form restore message 11 const int SC _RESTORE = 61728; 12 13 // form button blocking function 14 protected override void WndProc (ref Message m) 15 {16 17 if (m. msg = WM_SYSCOMMAND) 18 {19 // If m. WParam. toInt32 () = SC _RESTORE T Hen20 // 'block restore button 21 // Exit Sub22 // End If23 24 if (m. WParam. toInt32 () = SC _NOMAL) 25 {26 // block restore button 27 28 return; 29} 30 // if (m. WParam. toInt32 () = SC _MINIMIZE) 31 // {32 // The interception minimization button 33 /// write the operation code 34 35 // return here; 36 //} 37 if (m. WParam. toInt32 () = SC _MAXIMIZE) 38 {39 // intercept the form maximization button 40 //..................... 41 42 return; 43} 44 45 46 // form close message 47 if (m. WParam. toInt32 () = SC _CLOSE) 48 {49 if (MessageBox. show (" Are you sure you want to exit? "," ", MessageBoxButtons. OKCancel) = DialogResult. OK) 50 {51 System. environment. exit (System. environment. exitCode); 52} 53 else54 {55 return; 56} 57 58} 59} 60 base. wndProc (ref m); 61 62} 63 64 65}
VB
1 Const WM_SYSCOMMAND As Integer = & H112 2 Const SC _CLOSE As Integer = & HF060 'form close Message 3 Const SC _MINIMIZE As Integer = & HF020' form minimize Message 4 Const SC _MAXIMIZE As Integer = & HF030 'form maximize message 5 Const SC _NOMAL As Integer = & HF120 'form restore Message 6 Const SC _RESTORE As Integer = 61728' form restore Message 7 8' form button blocking function 9 Protected Overrides Sub WndProc (ByRef m As Message) 10 11 If m. msg = WM_SYSCOMMAND Then12 'if m. WParam. toInt32 () = SC _RESTORE Then13 ''block restore button 14 'exit sub15' End If16 17 If m. WParam. toInt32 () = SC _NOMAL Then18 'block restore button 19 20 Exit Sub21 End If22 If m. WParam. toInt32 () = SC _MINIMIZE Then23 'intercept minimization button 24' write operation code 25 26 Exit Sub27 End If28 If m. WParam. toInt32 () = SC _MAXIMIZE Then29 'intercept form maximization button 30 '..................... 31 32 Exit Sub33 End If34 'intercept double-click the title bar and move the system message of the Form 35 If m. msg <> & HA3 AndAlso m. msg <> & H3 AndAlso m. WParam <> & HF012 Then36 MyBase. wndProc (m) 37 End If38 39 If m. WParam. toInt32 () = SC _CLOSE Then40 41 Exit Sub42 43 End If44 End If45 MyBase. wndProc (m) 46 47 End SubView Code
The "minimize, maximize, or close" button is not displayed.
This. ControlBox = false; // The close button is not displayed.