Zedgraphcontrol缩放代码

时间:2013-07-24 11:59:44

标签: c# zedgraph

我想使用表单上的按钮放大zedgraphcontrol 为mouseWheel提供的相同缩放...我不知道如何。 我已经从zedgraph源代码中复制了一些代码,但只是缩小工作正常。

当我通过Delta -1时,它会缩小...它可以正常工作。 但是当我通过Delta 1时,它会放大......但它没有。 任何想法?

    private void Zoom(int Delta, int ZoomStepFraction)
    {
        if ((zedGraphControl1.IsEnableVZoom || zedGraphControl1.IsEnableHZoom) && zedGraphControl1.MasterPane != null)
        {
            GraphPane pane = zedGraphControl1.GraphPane;
            if (pane != null && Delta != 0)
            {
                PointF centerPoint = new PointF(zedGraphControl1.Size.Width / 2, zedGraphControl1.Size.Height / 2);
                double zoomFraction = (1 + (Delta < 0 ? 1.0 : -1.0) * ZoomStepFraction);

                zedGraphControl1.ZoomPane(pane, zoomFraction, centerPoint, false);

                ApplyToAllPanes(pane);

                using (Graphics g = this.CreateGraphics())
                {
                    // always AxisChange() the dragPane
                    pane.AxisChange(g);

                    foreach (GraphPane tempPane in zedGraphControl1.MasterPane.PaneList)
                    {
                        if (tempPane != pane && (zedGraphControl1.IsSynchronizeXAxes || zedGraphControl1.IsSynchronizeYAxes))
                            tempPane.AxisChange(g);
                    }
                }

                zedGraphControl1.Refresh();

            }
        }
    }


    private void ApplyToAllPanes(GraphPane primaryPane)
    {
        foreach (GraphPane pane in zedGraphControl1.MasterPane.PaneList)
        {
            if (pane != primaryPane)
            {
                if (zedGraphControl1.IsSynchronizeXAxes)
                    Synchronize(primaryPane.XAxis, pane.XAxis);
                if (zedGraphControl1.IsSynchronizeYAxes)
                    Synchronize(primaryPane.YAxis, pane.YAxis);
            }
        }
    }


    private void Synchronize(Axis source, Axis dest)
    {
        dest.Scale.Min = source.Scale.Min;
        dest.Scale.Max = source.Scale.Max;
        dest.Scale.MajorStep = source.Scale.MajorStep;
        dest.Scale.MinorStep = source.Scale.MinorStep;
        dest.Scale.MinAuto = source.Scale.MinAuto;
        dest.Scale.MaxAuto = source.Scale.MaxAuto;
        dest.Scale.MajorStepAuto = source.Scale.MajorStepAuto;
        dest.Scale.MinorStepAuto = source.Scale.MinorStepAuto;
    }

1 个答案:

答案 0 :(得分:0)

为了禁用 MouseWheel Zoom Event

zedGraphControl1.IsEnableWheelZoom = false;

&安培;

Zedgraph 提供缩放作为默认功能,例如:平移,放大,缩小,可根据需要进行自定义。

enter image description here