Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I wirte a window application, and I dwew a ContextMenuStrip object to my program to be included in a panel object, so that when I right click mouse on the panel, the ContextMenuStrip will pop up automatially.

And now, the question is that when I click and hold left button of mouse, and then right click mouse, I hope the ContextMenuStrip will not pop up anyway, but, the ContextMenuStrip still pop up there !

Can anybody help to show how to reach this point ?
Posted

Handle MouseDown event of Panel.
Check the sample code here.
C#
private void panel3_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        panel3.ContextMenuStrip = contextMenuStrip3;
    }
    else
    {
        panel3.ContextMenuStrip = null;
    }
}


[Added code formatting]
 
Share this answer
 
v3
Comments
Sports Kuo 20-Sep-10 7:03am    
Thanks of your answer, it's clear to me and sounds works !
you may disable contextMenuStrip in left mouse click event and enable it in leave event
:suss:
 
Share this answer
 
v2
Comments
Sports Kuo 20-Sep-10 5:48am    
Thanks of your answer, but my question is still below, please show detail answer to me.

I add one line in left mouse click event : ConTextMenuStrip1.Enabled=false;
but, when I right click on panel, it still pop up the ConTextMenuStrip, though it is disabled.
Can you show detail answer to exactly stop the popup of ContextMenuStrip ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900