C # to implement the system tray and form to minimize the hidden as a taskbar icon window appllication

Source: Internet
Author: User

1. Set form Properties Showintask=false

2. Add the NotifyIcon control Notifyicon1, adding an icon icon for the property icon of the control Notifyicon1.

3. Add form Minimize event (you need to add an event reference first):

//this.sizechanged+=newsystem.eventhandler(this.form1_sizechanged);
//上面一行是主窗体initializecomponent()方法中需要添加的引用 
privatevoidform1_sizechanged(objectsender,eventargse)
{
if(this.windowstate==formwindowstate.minimized)
{
this.hide();
this.notifyicon1.visible=true;
}
}

4. Add Click Icon Event (first need to add event reference):

privatevoidnotifyicon1_click(objectsender,eventargse)
{
this.visible=true;
this.windowstate=formwindowstate.normal;
this.notifyicon1.visible=false;
}

5. You can add the right button menu to NotifyIcon:

Drag a ContextMenu control contextmenu1 the main form, click the Control, add a menu to the context menu, and select Contextmenu1 as the context menu in the ContextMenu behavior of the notifyicon1.

(You can add behavior to the submenu)

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.