C # how to minimize the program to the system tray in winform

Source: Internet
Author: User

1. Add a policyicon control to form.

2. Place the 87. ico icon in the \ bin \ Debug directory.

 

Code
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;

The namespace minimizes the program to the system tray
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

Private void Form1_Load (object sender, EventArgs e)
{
This. policyicon1 = new System. Windows. Forms. policyicon (this. components );
Policyicon1.icon = new Icon ("87.ico"); // specify an Icon
Policyicon1.visible = false;
Policyicon1.click + = new System. EventHandler (this. policyicon#click );
This. SizeChanged + = new System. EventHandler (this. Form1_SizeChanged );


}

Private void Form1_SizeChanged (object sender, EventArgs e)
{
If (this. WindowState = FormWindowState. Minimized) // minimize
{
This. ShowInTaskbar = false;
This. policyicon1.visible = true;
}

}

Private void policyicon#click (object sender, EventArgs e)
{
If (this. WindowState = FormWindowState. Minimized)
This. WindowState = FormWindowState. Normal;
This. Activate ();
This. policyicon1.visible = false;
This. ShowInTaskbar = true;

}

}
}

 

 

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.