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?
Asked
Active
Viewed 3,167 times
1 Answers
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