2012-08-09 177 views
1

在ZedGraph窗格上,可以将CurveItem设置为“已选中”。更改zedgraph选择的曲线颜色

zedGraphControl.GraphPane.CurveList[0].IsSelected = true; 
zedGraphControl.Refresh(); 

据我所知,这将改变它的颜色为Color.Gray

是否可以更改此选定状态颜色?

回答

4

我不知道这样的属性,但你可以通过手动重写ZedGraphControl的鼠标点击事件做到这一点,并设置“选择” CurveItem的颜色,喜欢的东西:

private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e) 
    { 
     foreach (var curve in zedGraphControl1.GraphPane.CurveList) 
     { 
      curve.Color = Color.Black; 
     } 

     CurveItem nearestItem; 
     int nearestPoint; 
     zedGraphControl1.GraphPane.FindNearestPoint(e.Location, out nearestItem, out nearestPoint); 
     if (nearestItem != null) 
     { 
      nearestItem.Color = Color.Red; 
     } 
     zedGraphControl1.Refresh(); 
    } 

UPDATE:看看http://www.opensourcejavaphp.net/csharp/zedgraph/Line.cs.htmlhttp://www.opensourcejavaphp.net/csharp/zedgraph/Selection.cs.html的源代码,似乎Line.DrawCurve正在使用静态属性Selection.Line。不修改源代码将很难改变这种行为。 Line.cs的

部分:

public void DrawCurve(Graphics g, GraphPane pane, CurveItem curve, float scaleFactor) 
{ 
    Line source = this; 
    if (curve.IsSelected) 
     source = Selection.Line; 

Selection.cs:

/// The <see cref="Line" /> type to be used for drawing "selected" 
/// <see cref="LineItem" /> and <see cref="StickItem" /> types 
/// </summary> 
public static Line Line = new Line(Color.Gray); 
+0

是的,谢谢,这就是我已经做的。后来我发现了IsSelected属性,所以我想知道我是否可以使用它。 – Otiel 2012-08-09 07:35:14

+0

请参阅更新。 – HischT 2012-08-10 11:35:17

+0

因此,修改源代码不会改变。我可以接受:) – Otiel 2012-08-10 12:07:33

0

所选择的线路静态属性,而不是只读的。可以通过重置Selection.Line属性来更改格式:

public Form1() 
{ 
    InitializeComponent(); 
    ZedGraph.Selection.Line.Width = 3; 
    ZedGraph.Selection.Line.Color = Color.Red; 
    ... 
} 

重置选择行后,所有选定的行将按指定绘制。