Enabling mouse wheel zooming in a Microsoft Chart Control

后端 未结 2 1736
情书的邮戳
情书的邮戳 2020-12-20 17:24

how to enable zooming in Microsoft chart control by using Mouse wheel

I have the below code, i need to know how to make this event? in which class it is..

         


        
相关标签:
2条回答
  • 2020-12-20 18:13

    I think the above answer should be,

    chData.MouseWheel += new MouseEventHandler(chData_MouseWheel);

    But according to what I found out, chart's mouse-wheel doesn't work as long as you don't set focus on the chart control in your code. So I used mouse-enter of the chart control to set focus to the chart and mouse leave event of the chart control to set the control back to its parent.

    So you need to add below lines to your code, bind the mouse leave and mouse enter events of the chart control correspondingly plus add the above line too.

        private void chartTracking_MouseEnter(object sender, EventArgs e)
        {
            this.chartTracking.Focus();
        }
    
        private void chartTracking_MouseLeave(object sender, EventArgs e)
        {
            this.chartTracking.Parent.Focus();
        }
    
    0 讨论(0)
  • 2020-12-20 18:19

    What you have is an handler method for the MouseWheel event. You need to attach your handler method to the MouseWheel event for the chart control. From the method signature, I assume that your chart control is named chData, so you could use the following code in your form's constructor:

    chData.MouseWheel += new EventHandler(chData_MouseWheel);
    

    Of course, you could also associate the handler with the event at design time. To do that, use the Properties Window and click the lightning bolt in the toolbar to switch to the "Events" view. Then find the MouseWheel event, click the drop-down arrow, and select your handler method's signature. This will cause the designer to write the above code into the code-behind file for your form.

    Aside from that, there's a giant red flag in your code: an empty catch block. If you aren't handling an exception or doing anything with it, then you should not be catching it. This isn't Pokemon, there's no reward for catching them all.

    0 讨论(0)
提交回复
热议问题