Search code examples
c#colorszedgraph

Change zedgraph selected curve color


On a ZedGraph pane, it is possible to set a CurveItem as "selected".

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

This will change its color to Color.Gray as far as I can see.

Is it possible to change this selected-state color?


Solution

  • I don't know of such a property but you can accomplish this by manually overriding the MouseClick event of the ZedGraphControl and set the color of the "selected" CurveItem, something like:

    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: Looking at the source code of http://www.opensourcejavaphp.net/csharp/zedgraph/Line.cs.html and http://www.opensourcejavaphp.net/csharp/zedgraph/Selection.cs.html it seems that Line.DrawCurve is using static property Selection.Line. Without modifying source it would be hard to change this behaviour.

    Part of 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 );