Winform intercept Minimize, maximize, Close event "organize"

Source: Internet
Author: User

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 <> &AMP;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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.