首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单击ZedGraph窗格时绘制线条

在单击ZedGraph窗格时绘制线条
EN

Stack Overflow用户
提问于 2012-09-14 18:09:15
回答 1查看 5.3K关注 0票数 1

我对ZedGraph有一点不同的要求。

我想在用户单击ZedGraph窗格时在ZedGraph窗格上创建曲线。此外,我还在该窗格上绘制了其他图形。但我希望每当用户点击zedGraph区域时,我们就会得到用户点击的坐标,然后我在点击的坐标上画一条直线。

我在FindNearestObject方法中使用了MouseCLick事件alogn,如下所示:

代码语言:javascript
复制
private void zedGraph_RenderedTrack_MouseClick(object sender, EventArgs e)
    {
        MouseEventArgs xx = (MouseEventArgs)e;
        object nearestObject;
        int index;
        this.zedGraph_RenderedTrack.GraphPane.FindNearestObject(new PointF(xx.X, xx.Y), this.CreateGraphics(), out nearestObject, out index);
        if (nearestObject != null)
        {
            DrawALine(xx.X, Color.Red, true);
        }
    } 

但是使用这个,ZedGraph会搜索一些曲线,找到最近的点,然后绘制这条线,但我希望这条线是在用户点击的地方绘制的。有什么方法可以做到这一点吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-14 23:07:31

您可以尝试下面的代码,它将为鼠标单击事件绘制一条垂直线。

代码语言:javascript
复制
public Form1()
    {
        InitializeComponent();
    }        

    PointPairList userClickrList = new PointPairList();
    LineItem userClickCurve = new LineItem("userClickCurve");

    private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e)
    {
        // Create an instance of Graph Pane
        GraphPane myPane = zedGraphControl1.GraphPane;

        // x & y variables to store the axis values
        double xVal;
        double yVal;

        // Clear the previous values if any
        userClickrList.Clear();

        myPane.Legend.IsVisible = false;

        // Use the current mouse locations to get the corresponding 
        // X & Y CO-Ordinates
        myPane.ReverseTransform(e.Location, out xVal, out yVal);

        // Create a list using the above x & y values
        userClickrList.Add(xVal, myPane.YAxis.Scale.Max);
        userClickrList.Add(xVal, myPane.YAxis.Scale.Min);

        // Add a curve
        userClickCurve = myPane.AddCurve(" ", userClickrList, Color.Red, SymbolType.None);

        zedGraphControl1.Refresh();
    }

您只需更改userClickList即可绘制水平线。

快乐编码...:)

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12422398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档