如何禁用ContextMenuStrip的弹出窗口 [英] How to disable the pop up of ContextMenuStrip

查看:127
本文介绍了如何禁用ContextMenuStrip的弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个窗口应用程序,然后将ContextMenuStrip对象拖到要包含在面板对象中的程序中,以便当我在面板上单击鼠标右键时,ContextMenuStrip将自动弹出.

现在的问题是,当我单击并按住鼠标左键,然后右键单击鼠标时,我希望ContextMenuStrip仍然不会弹出,但是ContextMenuStrip仍然会弹出那里!

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 ?

推荐答案

处理PanelMouseDown event.
在此处检查示例代码.
Handle MouseDown event of Panel.
Check the sample code here.
private void panel3_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        panel3.ContextMenuStrip = contextMenuStrip3;
    }
    else
    {
        panel3.ContextMenuStrip = null;
    }
}



[添加的代码格式]



[Added code formatting]


您可以在鼠标左键单击事件中禁用contextMenuStrip,在离开事件中启用它
:suss:
you may disable contextMenuStrip in left mouse click event and enable it in leave event
:suss:


这篇关于如何禁用ContextMenuStrip的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆