Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MS图表c中的缩小功能#_C#_Winforms_Zooming_Mschart - Fatal编程技术网

C# MS图表c中的缩小功能#

C# MS图表c中的缩小功能#,c#,winforms,zooming,mschart,C#,Winforms,Zooming,Mschart,我有以下Winforms代码: void chart1_MouseWheel(object sender, MouseEventArgs e) { double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum; double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum; if (

我有以下Winforms代码:

void chart1_MouseWheel(object sender, MouseEventArgs e)
        {
            double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
            double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
            if (e.Delta < 0)
            {   //chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
                //chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
            }

            if (e.Delta > 0)
            {
                double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/2 ;
                double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/2;
                chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
            }
        }
void chart1\u鼠标滚轮(对象发送器,鼠标指针)
{
double xMin=chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax=chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
如果(e.Delta<0)
{//chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
//chart1.ChartAreas[0]。AxisY.ScaleView.ZoomReset();
}
如果(e.Delta>0)
{
double posXStart=chart1.ChartAreas[0].axix.PixelPositionToValue(e.Location.X)-(xMax-xMin)/2;
double posXFinish=chart1.ChartAreas[0].axix.PixelPositionToValue(e.Location.X)+(xMax-xMin)/2;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart,posXFinish);
}
}
放大功能正在工作,但当
e.Delta<0
时,我需要基于上述代码的缩小功能

试试看

chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(1);
chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset(1);
如果在缩放时将saveState设置为true,则ZoomReset(1)将返回到上次缩放状态。或者,如果将saveState设置为false,ZoomReset(1)将一直缩小。这是我的代码,我用鼠标点击来完成我的代码,但我相信你可以用滚轮来完成它:

    private void chart1_SelectionRangeChanged(object sender, CursorEventArgs e)
    {
        double startX, endX, startY, endY;

        if (chart1.ChartAreas[0].CursorX.SelectionStart > chart1.ChartAreas[0].CursorX.SelectionEnd)
        {
            startX = chart1.ChartAreas[0].CursorX.SelectionEnd;
            endX = chart1.ChartAreas[0].CursorX.SelectionStart;
        }
        else
        {
            startX = chart1.ChartAreas[0].CursorX.SelectionStart;
            endX = chart1.ChartAreas[0].CursorX.SelectionEnd;
        }
        if (chart1.ChartAreas[0].CursorY.SelectionStart > chart1.ChartAreas[0].CursorY.SelectionEnd)
        {
            endY = chart1.ChartAreas[0].CursorY.SelectionStart;
            startY = chart1.ChartAreas[0].CursorY.SelectionEnd;
        }
        else
        {
            startY = chart1.ChartAreas[0].CursorY.SelectionStart;
            endY = chart1.ChartAreas[0].CursorY.SelectionEnd;
        }

        if (startX == endX && startY == endY)
        {
            return;
        }

        chart1.ChartAreas[0].AxisX.ScaleView.Zoom(startX, (endX - startX), DateTimeIntervalType.Auto, true);
        chart1.ChartAreas[0].AxisY.ScaleView.Zoom(startY, (endY - startY), DateTimeIntervalType.Auto, true);
    }

因为您可以使用
ZoomReset(1)
方法返回缩放历史中的一个步骤。但是,如果使用
ZoomReset(0)
可以重置所有缩放操作,而无需关闭历史记录保存。

旧帖子,但要返回到第一级缩放,所花费的时间可能非常长,因此,请尽快执行,如下所示:while(chart1.ChartAreas[0].AxisX.ScaleView.IsZoomed){chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset(100);}并且不要忘记对所有使用的axis执行此操作,无需为此使用循环。根据,使用ZoomReset(0)重置所有缩放操作。感谢@NarcísCalvet-我已经用你的建议更新了我的答案。