Compared with C ++, The NotifyIcon control provided by c # makes it much easier to implement the tray icon.
Pallet Program Production:
1. Drag the yyicon control to the form and set the Icon of the NotifyIcon (very important! Otherwise, no effect will be displayed after running)
2. Minimize the control form to the tray.
Click (here) to fold or open
Private void MinToIcon ()
{
This. Hide ();
This. ShowInTaskbar = false;
This. policyiconctrl. Visible = true;
}
Private void ShowDlg ()
{
This. Show ();
This. ShowInTaskbar = true;
This. policyiconctrl. Visible = false;
}
3. Create a menu item: "display main form", "exit", and attach the menu to policyicon.
Click (here) to fold or open
Private MenuItem showDlgMenu = new MenuItem ("display form ");
Private MenuItem exitMenu = new MenuItem ("exit ");
This. showDlgMenu. Click + = new EventHandler (showDlgMenu_Click );
This. exitMenu. Click + = new EventHandler (exitMenu_Click );
This. policyiconctrl. ContextMenu = new System. Windows. Forms. ContextMenu ();
This. policyiconctrl. ContextMenu. MenuItems. Add (this. showDlgMenu );
This. policyiconctrl. ContextMenu. MenuItems. Add (this. exitMenu );
Private void btnMinToIcon_Click (object sender, EventArgs e)
{
MinToIcon ();
}
Void showDlgMenu_Click (object sender, EventArgs e)
{
ShowDlg ();
}
Void exitMenu_Click (object sender, EventArgs e)
{
This. Dispose (true );
Application. ExitThread ();
}