When you click the Minimize button, the program is scaled to the system tray. When you double-click the system tray icon, the program is restored.
1. Create a winform project. Other operations are skipped.
2. Pull a policyicon control, set the property visable to false, and enter some files on the text property.
3. Implement the form sizechanged event. The Code is as follows:
If (this. windowstate = formwindowstate. Minimized) // determines whether to minimize
{
This. showintaskbar = false; // It is not displayed in the system taskbar.
Policyicon. Visible = true; // The tray icon is visible.
}
4. Implement the DoubleClick event of the policyicon control. The Code is as follows:
If (this. windowstate = formwindowstate. Minimized)
{
This. showintaskbar = true; // displayed on the system taskbar
This. windowstate = formwindowstate. Normal; // restore the form
Policyicon. Visible = false; // hide the tray icon
}
Other automatically generated code blocks
Public form1 ()
{
Initializecomponent ();
This. sizechanged + = new eventhandler (mainform_sizechanged );
This. policyicon1.doubleclick + = new eventhandler (policyicon#doubleclick );
}
Article to learn it Network: http://www.xueit.com/html/2011-12/103-21394779782011124200715470.html