4

I have a bar graph and I want to allow the user to right click a particular bar, select some operation (add one or anything really) that will affect only that bar. Is this type of thing possible using ZedGraph?

sooprise
  • 22,657
  • 67
  • 188
  • 276

1 Answers1

8

You can add a Mouse Click event to the Form and call FindNearestObject() passing in that mouse point, you'll get back the nearest object. Something like this perhaps:

private void zedGraphControl2_MouseClick(object sender, MouseEventArgs e)
{
    object nearestObject;
    int index;
    this.zedGraphControl2.GraphPane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out nearestObject, out index);
    if (nearestObject != null && nearestObject.GetType() == typeof(BarItem))
    {
        BarItem barItem = (BarItem)nearestObject;
        barItem[index].Y += 1;
        zedGraphControl2.Invalidate();
    }
} 
PeskyGnat
  • 2,454
  • 19
  • 22