From: http://www.cnblogs.com/ensure125/archive/2007/04/12/711024.html
The policyicon control is used. Remember to set the form showintaskbar to true/false. It is mainly used to control whether the form is displayed on the taskbar. Remember to set an image for the icon.
The Code is as follows:
1 // form minimization event
2 Private void pbminisize_click (Object sender, system. eventargs E)
3 {
4 // set the windowstate to normal if the form is minimized.
5 windowstate = formwindowstate. minimized;
6 // indicates whether to display the form in the Windows taskbar
7 This. showintaskbar = false;
8 notifyicon1.visible = true;
9}
10 # endregion
11
12 // double-click event in the taskbar Area
13 private void policyicon#doubleclick (Object sender, eventargs E)
14 {
15 // show the form when the user double clicks on the specified y icon.
16 if (this. windowstate = formwindowstate. Minimized)
17 this. windowstate = formwindowstate. normal;
18 this. Activate ();
19 this. showintaskbar = true;
20 This. policyicon1.visible = false;
21}
Use menuitem to set the click menu in the taskbar area.
// Exit
Private void menuitem1_click (Object sender, eventargs E)
{
This. Close ();
}
// Open
Private void menuitem2_click (Object sender, system. eventargs E)
{
This. windowstate = formwindowstate. normal;
This. Activate ();
This. showintaskbar = true;
This. policyicon1.visible = false;
}
C # Hide the window appllication as the taskbar icon when writing the minimal code
From: http://lybabiandbel.cnblogs.com/archive/2006/01/09/313886.html
1. Set form attribute showintask = false
2. Add the policyicon control policyicon1 to add an icon for the property icon of the control policyicon1.
3. Add a form minimization event (you must first add an event reference ):
// 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;
}
}
4. 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;
}
5. 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)