Some applicationsProgramIt runs for a long time, but does not want it to occupy the taskbar. You also want to call up the results frequently. At this time, you can use a torch program.
. Net Implementation of the pallet program is not complex, the basic principle is like this:
1. Drag a policyicon control to the application form. In fact, the pallets are called notification areas in Microsoft's standard format, so the control name is policyicon.
2. assign an icon class instance to the icon attribute of policyicon, that is, set the icon.
3. assign a contextmenu class instance to the contextmenu attribute of yyicon. when instantiating the contextmenu, You can input a parameter of the menuitem [] type in the contextmenu function, each menuitem has a text attribute and a click event. You can right-click the tray icon.
4. subscribe to the click event of yyicon and set the visible of form to true in the event response function.
5. subscribe to the form closing event. In the event response function, set the formclosingeventargs. Cancel attribute to true and set the visible of form to false. When the vertex is closed, the form is hidden.
ImplementationCodeAs follows:
Private Bool Isexit;
Public Frmmain ()
{
Initializecomponent ();
If (File. exists ( " Monitor. ICO " ))
{
Yyicon. icon = New Icon ( " Monitor. ICO " );
Menuitem [] traymenu = New Menuitem [ 3 ];
Menuitem startitem = New Menuitem ();
Startitem. Text = " Start " ;
Startitem. Click + = New Eventhandler (startitem_click );
Menuitem stopitem = New Menuitem ();
Stopitem. Text = " Stop " ;
Stopitem. Click + = New Eventhandler (stopitem_click );
Menuitem exititem = New Menuitem ();
Exititem. Text = " Exit " ;
Exititem. Click + = New Eventhandler (exititem_click );
Traymenu [ 0 ] = Startitem;
Traymenu [ 1 ] = Stopitem;
Traymenu [ 2 ] = Exititem;
Notifyicon. contextmenu = New Contextmenu (traymenu );
Policyicon. Click + = New Eventhandler (policyicon_click );
}
Isexit = False ;
}
Void Notifyicon_click ( Object Sender, eventargs E)
{
This. Visible= True;
}
Void Startitem_click ( Object Sender, eventargs E)
{
}
Void Stopitem_click ( Object Sender, eventargs E)
{
}
Void Exititem_click ( Object Sender, eventargs E)
{
Isexit= True;
Close ();
}
Private Void Frmmain_formclosing ( Object Sender, formclosingeventargs E)
{
If ( ! Isexit)
{
E. Cancel= True;
This. Visible= False;
}
}
}
}