Display the minimal icon of the winform application on the taskbar and provide a right-click menu

Source: Internet
Author: User
    1. First, set the MDI form showintaskbar to true. In vs2008, the default value is true;
    2. Add the policyicon and its contextmenustrip controls respectively;
    3. 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;
    4. Add a mousedoubleclick event named yyiconsystem_mousedoubleclick for policyicon;
    5. 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!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.