CopyCodeThe Code is as follows: // This. sizechanged + = new system. eventhandler (this. form1_sizechanged );
// The above line is the reference to be added in the main form initializecomponent () method
Private void form1_sizechanged (Object sender, eventargs E)
{
If (this. windowstate = formwindowstate. Minimized)
{
This. Hide ();
This. policyicon1.visible = true;
}
}
. Add a click icon event (you must first add an event reference ):
Private void policyicon#click (Object sender, eventargs E)
{
This. Visible = true;
This. windowstate = formwindowstate. normal;
This. policyicon1.visible = false;
}
. You can right-click policyicon to add a menu:
In the main form, drag a contextmenu control contextmenu1, click the control, and add a menu in the context menu. In the contextmenu action of notifyicon1, select contextmenu1 as the context menu.
(You can add actions in the sub-menu)