C # operation steps and implementation code for minimizing program to tray icon

Source: Internet
Author: User

CopyCodeThe Code is as follows: // This. sizechanged + = new system. eventhandler (this. form1_sizechanged );
// The above line is the reference to be added in the main form initializecomponent () method
Private void form1_sizechanged (Object sender, eventargs E)
{
If (this. windowstate = formwindowstate. Minimized)
{
This. Hide ();
This. policyicon1.visible = true;
}
}
. 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;
}
. You can right-click policyicon to add a menu:
In the main form, drag a contextmenu control contextmenu1, click the control, and add a menu in the context menu. In the contextmenu action of notifyicon1, select contextmenu1 as the context menu.
(You can add actions in the sub-menu)

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.