C # minimize the WinForm window to the system tray code and determine the left and right mouse events,
1. Set the WinForm attribute showinTask to 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 refers to the reference 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:
Drag a contextMenuStrip control into the main form and add a menu in NicontextMenu. In the ContextMenu action of notifyIcon1, select NicontextMenu as the context menu.
6. Determine the left and right mouse events
Click the yyicon control and enter the code.
// NotifyIcon1 mouse event click (for example, double-click Select double-click event) private void policyicon#mouseclick (object sender, MouseEventArgs e) {if (e. button = MouseButtons. left & e. clicks = 1) {// left} else if (e. button = MouseButtons. right & e. clicks = 1) {// right }}