- First, set the MDI form showintaskbar to true. In vs2008, the default value is true;
- Add the policyicon and its contextmenustrip controls respectively;
- Then, point the contextmenustrip attribute value of yyicon to contextmenustrip, and specify the icon of notifyicon as a *. Icon image file to display in the taskbar;
- Add a mousedoubleclick event named yyiconsystem_mousedoubleclick for policyicon;
- Add a sizechanged event named mainform_sizechanged to the MDI form;
The above can basically fulfill our corresponding needs, and then we can achieve it. Here, I want the application to display no corresponding icon in the taskbar when it is in the application, and display its icon only when it is minimized, and right-click the icon on the taskbar to provide simple functions (hide, show, close, about), double-click the icon to restore the application form.
DetailsCodeAs follows:
Code
// Form Loading
Private Void Mainform_load ( Object Sender, eventargs E)
{
// .
This . Policyiconsystem. Visible = False ;
}
// Double-click the taskbar icon to restore the window
Private Void Notifyiconsystem_mousedoubleclick ( Object Sender, mouseeventargs E)
{
If ( This . Windowstate = Formwindowstate. Minimized)
This . Windowstate = Formwindowstate. normal;
This . Activate ();
This . Policyiconsystem. Visible = False ;
}
// Add form minimization event
Private Void Mainform_sizechanged ( Object Sender, eventargs E)
{
If ( This . Windowstate = Formwindowstate. Minimized) // Minimize
{
This . Showintaskbar = False ;
This . Policyiconsystem. Visible = True ;
}
}
# RegionBegin _ minimized right-click the icon menu
Private Void Menuitemicon_hide_click ( Object Sender, eventargs E)
{
// This. windowstate = formwindowstate. minimized;
This . Hide ();
This . Showintaskbar = False ;
This . Policyiconsystem. Visible = True ;
}
private void menuitemicon_show_click ( Object sender, eventargs e)
{< br> This . show ();
This . windowstate = formwindowstate. normal;
This . activate ();
}
Private VoidMenuitemicon_about_click (ObjectSender, eventargs E)
{
//
}
Private VoidMenuitemicon_exit_click (ObjectSender, eventargs E)
{
Applicationexit (Null);
}
# EndregionEnd _ minimized right-click the icon menu
I am a beginner in winform development. The above content is for personal purposes and can be used as needed. If it is incorrect, please help us with correction. Thank you very much! Blackcore!