1. Set WinForm Form Properties Showintask=false
2. Add NotifyIcon control NotifyIcon1, adding an icon to the property icon for the control NotifyIcon1.
3. Add a form Minimize event (you need to add an event reference first):
this . SizeChanged + = new System.EventHandler (this . form1_sizechanged); // The above line is the main form InitializeComponent () The reference that you need to add in the method private void form1_ SizeChanged (object sender, EventArgs e) { if (this . WindowState == formwindowstate.minimized) { . Hide (); true
4. Add a click Icon event (you need to add an event reference first):
private void Notifyicon1_click (object sender, EventArgs e)
{
This. Visible = true;
This. WindowState = Formwindowstate.normal;
This.notifyIcon1.Visible = false;
}
5. You can add a right-click menu to NotifyIcon:
Drag a ContextMenuStrip control into the main form, add a menu in Nicontextmenu, and NotifyIcon1 Nicontextmenu as the context menu in the ContextMenu behavior.
6. Judging the left and right mouse events
Click on the NotifyIcon control, enter the code
NotifyIcon1 Mouse Event Click (for example, double-click to select Double-click event) private void Notifyicon1_mouseclick (object sender, MouseEventArgs e) { if (E.button = = MouseButtons.Left && E.clicks = = 1) {//Left } else if (E.button = = Mousebuttons.right && E.clicks = = 1) {//Right } }
C # implements the WinForm window to minimize the system tray code, and to determine the left and right mouse events