Skip to main content
 首页 » 编程设计

c#之更改 zedgraph 选定的曲线颜色

2024年02月20日14luoye11

在 ZedGraph 面板上,可以将 CurveItem 设置为“选中”。

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

据我所知,这会将其颜色更改为 Color.Gray。

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

请您参考如下方法:

我不知道有这样的属性,但您可以通过手动覆盖 ZedGraphControl 的 MouseClick 事件并设置“选定”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(); 
    } 

更新:查看http://www.opensourcejavaphp.net/csharp/zedgraph/Line.cs.html的源代码和 http://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; 

选择.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 );