gpt4 book ai didi

c# - 单击 ZedGraph Pane 上的画线

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:55 27 4
gpt4 key购买 nike

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

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

我已将 MouseCLick 事件 alogn 与 FindNearestObject 方法一起使用,如下所示:

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 搜索一些曲线并找到最近的点,然后绘制线,但我希望在用户点击的地方绘制线。有什么方法可以做到吗?

最佳答案

你可以试试下面的代码,它会为鼠标点击事件绘制一条垂直线。

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

enter image description here

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

快乐编码......:)

关于c# - 单击 ZedGraph Pane 上的画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422398/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com