dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C#
Expertise: Intermediate
Dec 12, 2005

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


How to Hide a ContextMenu

To display the shortcut menu, you call ContextMenu.Show() method. Typically, you call this method if the right mouse button on a control or area of the form is clicked. The following snippet demonstrates this:

private void myControl_MouseUp(object sender,
                  System.Windows.Forms.MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
        myControl.ContextMenu.Show(myControl,
            new Point(e.X, e.Y) );      
}
After an item on the ContextMenu is selected and clicked, the ContextMenu, generally, should be hidden. It will happen "automatically" if you display another GUI component in response to this click.

In some cases, when you are not updating the screen, the ContextMenu stays on the screen after the click. In order to hide the ContextMenu, call the SendKeys.Send() method and pass the {ESC} code, as follows:


private void menuItemDoSomething_Click(object sender,
                   System.EventArgs e)
{
    //Your Code are here
    SendKeys.Send("{ESC}");
}
Boris Eligulashvili
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date