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