没有发射mouseWheel事件 [英] Mousewheel event not firing

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

问题描述

我看了这个线程关于完全相同的问题,但这种解决方案并没有为我工作。

基本上我试图做到的是,当用户与图表控件在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!

推荐答案

该chartcontrol需要把重点放在让鼠标滚轮事件可以触发。您可以将焦点设置当鼠标在控制进入,并给予重点其父回来的时候就离开了。

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();
}

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

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