鼠标右键单击 propertyGridControl 不起作用

发布于 2024-10-21 12:41:17 字数 352 浏览 4 评论 0原文

我正在处理 propertyGridControl 上的 Click 和 MouseClick 这两个事件,但是当我用右键单击时没有任何反应 - 它只捕获左侧。

private void propertyGridControl_Click(object sender, EventArgs e)
    {
        int i = 0;
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            MessageBox.Show("right");
        }
    }

如何捕获鼠标右键?

I am handling both events Click and MouseClick on propertyGridControl but when I click with right button nothing happens - it catches only left.

private void propertyGridControl_Click(object sender, EventArgs e)
    {
        int i = 0;
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            MessageBox.Show("right");
        }
    }

How to catch right mouse click?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2024-10-28 12:41:17

我已经检查了 MouseClick 事件的工作原理,但没有看到此问题。事件已正确引发。我检查了 PropertyGridControl 10.2.5(最新版本)。我只能想象您正在网格编辑器内单击。在这种情况下,鼠标和键盘事件由就地编辑器而不是网格管理。要捕获此事件,您可以使用以下代码:

private void propertyGridControl1_ShownEditor(object sender, EventArgs e) {
    PropertyGridControl pgc = sender as PropertyGridControl;
    pgc.ActiveEditor.MouseClick -= new MouseEventHandler(ActiveEditor_MouseClick);
    pgc.ActiveEditor.MouseClick += new MouseEventHandler(ActiveEditor_MouseClick);
}

void ActiveEditor_MouseClick(object sender, MouseEventArgs e) {
    if(e.Button == System.Windows.Forms.MouseButtons.Right) {
        MessageBox.Show("right");
    }            
}

我还有一个想法。如果设置了控件的 ContextMenuStrip 属性,则按下鼠标右键时不会引发 MouseClick 事件。是你的情况吗?解决方案很简单 - 处理控件的 MouseDown 事件。

I have checked how the MouseClick event works and do not see this issue. The event is correctly raised. I've checked 10.2.5 (latest version) of the PropertyGridControl. I can only imagine that you are clicking inside the grid's editor. In this case, mouse and keyboard events are managed by the in-place editor and not the grid. To catch this event, you may use the following code:

private void propertyGridControl1_ShownEditor(object sender, EventArgs e) {
    PropertyGridControl pgc = sender as PropertyGridControl;
    pgc.ActiveEditor.MouseClick -= new MouseEventHandler(ActiveEditor_MouseClick);
    pgc.ActiveEditor.MouseClick += new MouseEventHandler(ActiveEditor_MouseClick);
}

void ActiveEditor_MouseClick(object sender, MouseEventArgs e) {
    if(e.Button == System.Windows.Forms.MouseButtons.Right) {
        MessageBox.Show("right");
    }            
}

I have just one more idea. If the control's ContextMenuStrip property is set, the MouseClick event is not raised if the right mouse button is pressed. Is it your case? The solution is easy - handle the control's MouseDown event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文