C # The program is displayed as an icon in the lower right corner of the taskbar
Form minimization means that the entire form is reduced to the taskbar, but is displayed in the form of Form title bar,
To display the form in the lower-right corner of the taskbar as an icon, you must add a policyicon control to the form,
In the code that minimizes the form, you need to make the following changes:
If (this. windowstate = formwindowstate. normal & this. visible = true) {This. policyicon1.visible = true; // display form icon this in the notification area. windowstate = formwindowstate. minimized; this. visible = false; this. showintaskbar = false; // make the form not displayed on the taskbar}
In C #, display the minimize icon of the winform application on the taskbar and provide a right-click menu]
Minimize the winform window to the system tray, right-click the tray icon, and the exit menu is displayed.
1. Add the policyicon control myicon to the form, add an icon to the control's property icon, and text is the tip displayed when the mouse is on the icon.
2. Set the showintaskbar attribute of form in formateformclosing.
3. Set the showintaskbar and windowstate attributes of form in the myicon_mouseclick event.
4. Add the contextmenustrip control mymenu, right-click the tray icon to bring up the menu, and set the contextmenustrip attribute of myicon to mymenu. Add an item to mymenu (exit ).
5. In the mouseclick event, select right-click and pop up contextmenustrip.
Code:
Private void form=formclosing (Object sender, formclosingeventargs e) {If (E. closereason = closereason. userclosing) // {e. cancel = true; this. showintaskbar = false; this. myicon. icon = This. icon; this. hide () ;}} private void myicon_mouseclick (Object sender, mouseeventargs e) {If (E. button = mousebuttons. right) {mymenu. show ();} If (E. button = mousebuttons. left) {This. visible = true; this. windowstate = formwindowstate. normal;} private void toolmenucancel_click (Object sender, eventargs e) {application. exit ();}