(1) create a new project and modify the text attribute of form1 to testpolicyicon;
(2) Add a policyicon control to the form1 window and modify its name attribute to mypolicyicon. Modify the text attribute
Testpolicyicon and ApplicationProgram. This is because the text attribute is saved in the notifyicon when it is displayed in the system tray.
Text is the prompt message when you move the cursor over the program icon. Modify the icon attribute and add an icon to the categoryicon;
(3) In the form1 Properties window, select the icon attribute as the same as the policyicon. Modify the showintaskbar attribute
False. In this way, the application will not appear in the taskbar during running;
(4) event handling when you double-click policyiconCode(DoubleClick)
Private VoidMypolicyicon_doubleclick (ObjectSender, system. eventargs e ){If(This. Visible ){This. Hide ();}Else{This. Show ();}}
(5) When using the policyicon control, you often need to use the shortcut menu (contextmenu control) in the contextmenu attribute of the policyicon.
Select a shortcut menu. In this way, various functions of the program can be executed through the shortcut menu on the icon.
For example, add two functions to the shortcut menu: Display form, hide form, and exit program.
The code for clicking an event in the function is as follows:
private void display menu toolstripmenuitem_click ( Object sender, eventargs E) { This . show (); // display form }< span style = "color: # 0000ff "> private void hides the menu toolstripmenuitem_click ( Object sender, eventargs e) { This . hide (); // hide a form }< span style = "color: # 0000ff "> private void exit toolstripmenuitem_click ( Object sender, eventargs e) { This . close (); /// exit the Program }