0

是否可以使用鼠标事件“mouse_down 并按住”来缩放图形外的轴比例,并在 y 轴上向上或向下移动与 x 轴向左或向右移动相同?前任。当我触发 MouseDownEvent 并保持 x 轴刻度 0.6 或与该刻度一起保持空间并将其向右移动时,刻度应该滚动取决于图表分数吗?你能发布一个例子吗?提前致谢!

4

3 回答 3

1

可以使用 ZedGraph 的鼠标事件分别平移和缩放 Y 轴:、、和MouseDownEvent事件MouseMoveEvent(感谢我的同事)。MouseUpEventMouseWheel

它适用于多个 GraphPanes 和多个 Y 轴。

MouseMoveEvent用于在按下按钮时移动鼠标时移动 Y 轴的最小值和最大值。如果不是,则用于获取鼠标悬停在 Y 轴对象上的参考。

MouseDownEvent用于启动轴平移操作。

MouseWheel用于在 Y 轴上执行缩放。

并且MouseUpEvent用于在缩放和平移操作完成时清理东西。

这是代码:

// The axis that is currently hovered by the mouse
YAxis hoveredYAxis;

// The graphpane that contains the axis
GraphPane foundPane;

// The scale of the axis before it is panned
double movedYAxisMin;
double movedYAxisMax;

// The Y on the axis when the panning operation is starting
float movedYAxisStartY;

void z_MouseWheel(object sender, MouseEventArgs e)
{
    if (hoveredYAxis != null)
    {
        var direction = e.Delta < 1 ? -.05f : .05f;
        var increment = direction * (hoveredYAxis.Scale.Max - hoveredYAxis.Scale.Min);
        var newMin = hoveredYAxis.Scale.Min + increment;
        var newMax = hoveredYAxis.Scale.Max - increment;

        hoveredYAxis.Scale.Min = newMin;
        hoveredYAxis.Scale.Max = newMax;

        foundPane.AxisChange();

        z.Invalidate();
    }
}

bool z_MouseUpEvent(ZedGraphControl sender, MouseEventArgs e)
{
    hoveredYAxis = null;
    return false;
}

bool z_MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
{
    var pt = e.Location;

    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        if (hoveredYAxis != null)
        {
            var yOffset = hoveredYAxis.Scale.ReverseTransform(pt.Y) - hoveredYAxis.Scale.ReverseTransform(movedYAxisStartY);
            hoveredYAxis.Scale.Min = movedYAxisMin - yOffset;
            hoveredYAxis.Scale.Max = movedYAxisMax - yOffset;

            sender.Invalidate();
            return true;
        }
    }
    else
    {
        var foundObject = findZedGraphObject(null);
        hoveredYAxis = foundObject as YAxis;

        if (hoveredYAxis != null)
        {
            z.Cursor = Cursors.SizeNS;
            return true;
        }
        else
        {
            if (z.IsShowPointValues)
            {
                z.Cursor = Cursors.Cross;
                return false;
            }
            else
            {
                z.Cursor = Cursors.Default;
                return true;
            }
        }
    }

    return false;
}

bool z_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        if (hoveredYAxis != null)
        {
            movedYAxisStartY = e.Location.Y;
            movedYAxisMin = hoveredYAxis.Scale.Min;
            movedYAxisMax = hoveredYAxis.Scale.Max;
            return true;
        }
    }

    return false;
}

这是一个帮助器,它对 ZedGraph 的对象查找操作进行了一些分解。

object findZedGraphObject(GraphPane pane = null)
{
    var pt = zgc.PointToClient(Control.MousePosition);

    if (pane == null)
    {
        foundPane = zgc.MasterPane.FindPane(pt);
        if (foundPane != null)
        {
            object foundObject;
            int forget;

            using (var g = zgc.CreateGraphics())
                if (foundPane.FindNearestObject(pt, g, out foundObject, out forget))
                    return foundObject;
        }
    }

    return null;
}
于 2013-11-15T19:34:10.657 回答
0

你想创建一个滚动条吗?

 zedGraphControl1.IsShowHScrollbar = true;
//Set borders for the scale
zedGraphControl1.GraphPane.XAxis.Scale.Max = Xmax;
zedGraphControl1.GraphPane.XAxis.Scale.Min = Xmin;
于 2012-10-01T12:46:53.160 回答
0

如果我正确理解了您的问题,这是我的回答:

zedgraph 有一个名为“Pan”的内置函数,您可以更改 x 和 y 轴的比例。

将光标放在“图表区域”内按住“ctrl”按钮并将鼠标移向 x 和 y 方向以更改比例。

您可以通过“Un-Pan”(上下文菜单)恢复原始状态

干杯..:)

于 2012-09-07T16:49:35.250 回答