C # Write a Windows application that minimizes the system tray

Source: Internet
Author: User
window| Program

This is the case, in order to use their convenience, it is easy to write a watch network TV program. program minimized to the system tray, so when watching network TV, you can always open, at any time switch, more convenient, hehe.

Before in the Visual C + + programming environment, writing a system tray program like this should be more complicated and add the message processing function yourself. And in C #, it all becomes very easy. Here are the simple steps.

Add two main controls to the program, NotifyIcon controls and ContextMenu controls;

Set the Menu menu and the click event of the corresponding menu for ContextMenu;

Adds an icon icon to the property icon for the control NotifyIcon and selects the added ContextMenu for its contextmenu behavior as a context menu;

Set the Form property Showintask=false, set the form windowstate to minimized;

Add the event code to the InitializeComponent () method of the main form. SizeChanged + = new System.EventHandler (this. form1_sizechanged) and add the following SizeChanged event code

private void Form1_sizechanged (object sender, EventArgs e)

{

if (this. windowstate==formwindowstate.minimized)

{

This. Hide ();//Hidden main form

This.notifyicon1.visible=true;

}

} this. SizeChanged + = new System.EventHandler (this. form1_sizechanged) and add the following SizeChanged event code

private void Form1_sizechanged (object sender, EventArgs e)

{

if (this. windowstate==formwindowstate.minimized)

{

This. Hide ();//Hidden main form

This.notifyicon1.visible=true;

}

}

{

if (this. windowstate==formwindowstate.minimized)

{

This. Hide ();//Hidden main form

This.notifyicon1.visible=true;

}

}

After the program starts, it automatically minimizes to the system tray, right click on the tray icon to display the ContextMenu 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.