鼠标事件不发射 [英] Mousewheel event not firing

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

问题描述

我看过这个主题关于完全相同的问题,但该解决方案对我来说无效。

基本上我想要完成的是当用户与窗体上的图表控件交互时的鼠标滚轮事件。

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: p>

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

不幸的是,我不能得到darn的东西要开火?有谁能告诉我我哪里错了?感谢提前!

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天全站免登陆