When you usually click on the icon on the taskbar, the corresponding form implements the "Minimize or restore" effect. However, when minimizing to the tray, do not want to click the taskbar icon to minimize to the tray, that is, you want to intercept these effects (do not allow: by clicking on the taskbar icon, to achieve "minimize or restore" effect);
The specific implementation code is as follows:
#regionClick on the form icon in the taskbar (Minimize | restore) and click the Minimize buttonPrivate intWm_syscommand =0x112; Private LongSc_minimize =0xf020; protected Override voidWndProc (refMessage m) { if(M.msg = =Wm_syscommand) { if(M.wparam.toint64 () = = Sc_minimize && m.lparam.tostring ()! ="0")//m.lparam.tostring ()! = "0" means click on the form icon in the taskbar (minimized | recovery){hidemainform ();//here, the form diagram is directly formatted//this.isminboxhited = true; //Clicking on the Minimize button is not possible through the middle variable. return; } } Base. WndProc (refm); } #endregion
View Code
If you want to achieve other effects, you can refer to the following:
Private intWm_syscommand =0x112; Private LongSc_maximize =0xf030; Private LongSc_minimize =0xf020; Private LongSc_close =0xf060; protected Override voidWndProc (refMessage m) { if(M.msg = =Wm_syscommand) { if(M.wparam.toint64 () = =sc_maximize) { //MessageBox.Show ("maximize"); return; } if(M.wparam.toint64 () = =sc_minimize) { //MessageBox.Show ("MINIMIZE"); return; } if(M.wparam.toint64 () = =sc_close) { //MessageBox.Show ("CLOSE"); return; } } Base. WndProc (refm); }
View Code
C #: Isolate the "minimize or restore" effect when clicking on an icon on the taskbar