C # implement the tray icon

Source: Internet
Author: User

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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.