我详尽地使用了搜索,但一直未能找到令人满意的解决方案来解决我的问题。窗体窗体:在C#中的图表上创建透明图形
我使用图表(datavisualization.charting.chart)对数据可视化进行了编程。由于它显示了某种模拟结果,因此该图表稳步改变。 我想在图表上画一条线(取决于鼠标的位置),以便显示上下文相关的信息。
因此,我尝试了两种实现方式,既没有作品正是我想它:
情节主线上称为MouseMove-事件
GGRAPH从底层图使用创建:chartCreateGraphics() ;
protected void plotLine(object sender, System.EventArgs e)
{
if (this.chart.Series.Count > 0) //ensure that the chart shows data
{
plotChart(); // this plots the underlying chart
penGraph = new Pen(Color.Black);
Point point1 = new Point(Form1.MousePosition.X - chart.Location.X, 0);
Point point2 = new Point(Form1.MousePosition.X - chart.Location.X,
chart.Location.Y + chart.Size.Height);
gGraph.DrawLine(penGraph, point1, point2);
penGraph.Dispose();
}
}
在这里,每行绘制后立即消失,但应保持,只要鼠标不移动。
protected void plotLine(object sender, System.EventArgs e)
{
penGraph = new Pen(Color.Black);
Point point1 = new Point(Form1.MousePosition.X - chart.Location.X, 0);
Point point2 = new Point(Form1.MousePosition.X - chart.Location.X,
chart.Location.Y + chart.Size.Height);
gGraph.DrawLine(penGraph, point1, point2);
penGraph.Dispose();
}
这里,只要图表没有被新的图表绘制,所有绘制的线仍保留在图形表面中。 (只有最后一行应该保留为了表示鼠标位置)
任何人都可以帮我吗?
_gGraph是使用下面的图形创建的:chart.CreateGraphics(); _这是错误。 – TaW 2016-08-27 08:01:37