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.