启用鼠标滚轮缩放在Microsoft图表控件鼠标、缩放、图表、控件

2023-09-03 21:51:17 作者:沦入荒芜

如何启用放大微软图表控件使用鼠标滚轮

我有以下code,我需要知道如何使这个活动?其中类是..

 私人无效chData_MouseWheel(对象发件人,发送MouseEventArgs E)
{
    尝试
    {
        如果(e.Delta℃,)
        {
            chart1.ChartAreas [0] .AxisX.ScaleView.ZoomReset();
            chart1.ChartAreas [0] .AxisY.ScaleView.ZoomReset();
        }

        如果(e.Delta大于0)
        {
            双XMIN = chart1.ChartAreas [0] .AxisX.ScaleView.ViewMinimum;
            双XMAX = chart1.ChartAreas [0] .AxisX.ScaleView.ViewMaximum;
            双YMIN = chart1.ChartAreas [0] .AxisY.ScaleView.ViewMinimum;
            双YMAX = chart1.ChartAreas [0] .AxisY.ScaleView.ViewMaximum;

            双posXStart = chart1.ChartAreas [0] .AxisX.PixelPositionToValue(e.Location.X) - (XMAX  -  XMIN)/ 4;
            双posXFinish = chart1.ChartAreas [0] .AxisX.PixelPositionToValue(e.Location.X)+(XMAX  -  XMIN)/ 4;
            双posYStart = chart1.ChartAreas [0] .AxisY.PixelPositionToValue(e.Location.Y) - (YMAX  -  YMIN)/ 4;
            双posYFinish = chart1.ChartAreas [0] .AxisY.PixelPositionToValue(e.Location.Y)+(YMAX  -  YMIN)/ 4;

            chart1.ChartAreas [0] .AxisX.ScaleView.Zoom(posXStart,posXFinish);
            chart1.ChartAreas [0] .AxisY.ScaleView.Zoom(posYStart,posYFinish);
        }
    }
    抓住 { }
}
 

解决方案

我觉得上面的答案应该是,

chData.MouseWheel + =新MouseEventHandler(chData_MouseWheel);

但据我发现了什么,图的鼠标轮不只要你不设置侧重于图表控件在code工作。所以我用图表控件鼠标输入将焦点设置到图表控件图表和鼠标离开事件来控制设置回其父母。

所以,你需要下面的行添加到您的code,绑定鼠标离开和鼠标输入图表控件的事件,相应地加上添加上述行了。

 私人无效chartTracking_MouseEnter(对象发件人,EventArgs的)
    {
        this.chartTracking.Focus();
    }

    私人无效chartTracking_MouseLeave(对象发件人,EventArgs的)
    {
        this.chartTracking.Parent.Focus();
    }
 

项目 四 鼠标滚轮缩放图像

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..

private void chData_MouseWheel(object sender, MouseEventArgs e)
{
    try
    {
        if (e.Delta < 0)
        {
            chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
            chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
        }

        if (e.Delta > 0)
        {
            double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
            double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
            double yMin = chart1.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
            double yMax = chart1.ChartAreas[0].AxisY.ScaleView.ViewMaximum;

            double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin) / 4;
            double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin) / 4;
            double posYStart = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin) / 4;
            double posYFinish = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin) / 4;

            chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
            chart1.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish);
        }
    }
    catch { }            
}

解决方案

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