1 Const intWm_syscommand =0x112;2 //form Close Message3 Const intSc_close =0xf060;4 //form Minimized Messages5 Const intSc_minimize =0xf020;6 //form Maximization Message7 Const intSc_maximize =0xf030;8 //form Restore Message9 Const intSc_nomal =0xf120;Ten //form Restore Message One Const intSc_restore =61728; A - //blocking functions for form buttons - protected Override voidWndProc (refMessage m) the { - - if(M.msg = =wm_syscommand) - { + //If m.wparam.toint32 () = Sc_restore Then - //' intercept restore button + //Exit Sub A //End If at - if(M.wparam.toint32 () = =sc_nomal) - { - //Block Restore button - - return; in } - //if (m.wparam.toint32 () = = sc_minimize) to //{ + // //Intercept Minimized button - // //write the operation code here the * //return; $ //}Panax Notoginseng if(M.wparam.toint32 () = =sc_maximize) - { the //block form Maximize button + //..................... A the return; + } - $ $ //form Close Message - if(M.wparam.toint32 () = =sc_close) - { the if(MessageBox.Show ("Are you sure you want to exit? ","", messageboxbuttons.okcancel) = =DialogResult.OK) - {Wuyi System.Environment.Exit (System.Environment.ExitCode); the } - Else Wu { - return; About } $ - } - } - Base. WndProc (refm); A + } the - $}
Vb
1 ConstWm_syscommand as Integer= &H1122 ConstSc_close as Integer= &hf060'form Close Message3 ConstSc_minimize as Integer= &hf020'form Minimized Messages4 ConstSc_maximize as Integer= &hf030'form Maximization Message5 ConstSc_nomal as Integer= &hf120'form Restore Message6 ConstSc_restore as Integer=61728 'form Restore Message7 8 'blocking functions for form buttons9 Protected Overrides SubWndProc (ByRefM asMessage)Ten One Ifm.msg = Wm_syscommand Then A 'If m.wparam.toint32 () = Sc_restore Then - '' intercept restore button - 'Exit Sub the 'End If - - IfM.wparam.toint32 () = Sc_nomal Then - 'Block Restore button + - Exit Sub + End If A IfM.wparam.toint32 () = Sc_minimize Then at 'Intercept Minimized button - 'write the operation code here - - Exit Sub - End If - IfM.wparam.toint32 () = Sc_maximize Then in 'block form Maximize button - '..................... to + Exit Sub - End If the 'intercepts system messages that double-click the title bar and move the form * IfM.msg <> &HA3AndAlsoM.msg <> &h3AndAlsoM.wparam <> &hf012 Then $ MyBase. WndProc (m)Panax Notoginseng End If - the IfM.wparam.toint32 () = Sc_close Then + A Exit Sub the + End If - End If $ MyBase. WndProc (m) $ - End Sub
View Code
Minimize, Maximize, close buttons do not display
This false; // settings do not appear close button
Winform intercept Minimize, maximize, Close event "organize"