鼠标滚轮事件未触发 [英] Mousewheel event not firing

查看:63
本文介绍了鼠标滚轮事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过这个话题关于完全相同的问题,但该解决方案对我不起作用.
基本上我想要完成的是当用户与 Windows 窗体上的图表控件交互时的鼠标滚轮事件.
现在我已经尝试了一些不同的东西.

I've looked at this thread concerning the exact same problem but that solution didn't work for me.
Basically what I am trying to accomplish is a mouse wheel event when the user is interacting with a chart control on a windows form.
Right now I have tried a few different things.

 public mainForm()
 {
     InitializeComponent();
     this.chData.MouseWheel +=new MouseEventHandler(chData_MouseWheel);
 }

我也尝试将其添加到 mainForm.Designer.cs 中:

Also I have tried adding this to the mainForm.Designer.cs:

this.chData.TabIndex = 2;
this.chData.Text = "chart2";

this.chData.MouseWheel += 
   new System.Windows.Forms.MouseEventHandler(this.chData_MouseWheel);

this.chData.MouseClick += 
   new System.Windows.Forms.MouseEventHandler(this.chData_MouseClick);

this.chData.MouseDoubleClick += 
   new System.Windows.Forms.MouseEventHandler(this.chData_MouseDoubleClick);

this.chData.MouseMove += 
   new System.Windows.Forms.MouseEventHandler(this.chData_MouseMove);

(为了演示,我在这里包含了整个块).我也有如下定义的函数:

(I've included the whole block here for demonstration). I also have the function defined as such below:

private void chData_MouseWheel(object sender, MouseEventArgs e)
{
   MessageBox.Show("FJDKS");
}

不幸的是,我不能让这该死的东西开火?谁能告诉我我哪里出错了?提前致谢!

Unfortunately I can't get the darn thing to fire? Can anyone tell me where I am going wrong? Thanks in advance!

推荐答案

需要关注图表控件,以便触发鼠标滚轮事件.您可以在鼠标进入控件时设置焦点,离开时将焦点返回给其父级.

The chartcontrol needs to be focused on so the mousewheel event can fire. You can set the focus when the mouse enter in the control, and give the focus to its parent back when it leaves it.

void friendChart_MouseLeave(object sender, EventArgs e)
{
    if (friendChart.Focused)
        friendChart.Parent.Focus();
}

void friendChart_MouseEnter(object sender, EventArgs e)
{
    if (!friendChart.Focused)
        friendChart.Focus();
}

这篇关于鼠标滚轮事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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