Mousewheel event not firing

15,363

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();
}
Share:
15,363
tmwoods
Author by

tmwoods

Code writer (a bit of everything, mostly .NET), server admin (Linux/Windows), database (a bit of everything, mostly SQL-based). Spend most of my time herding cats and trying to get them to document their code.

Updated on June 02, 2022

Comments

  • tmwoods
    tmwoods about 2 years

    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!