private TextObj GetNearestLabel(PointF mousePoint) { using (Graphics g = CreateGraphics()) { object nearestObject; int index; if (GraphPane.FindNearestObject(mousePoint, g, out nearestObject, out index)) { var textObj = nearestObject as TextObj; if (textObj != null) return textObj; } } return null; }
private bool ZedGraphControl1_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e) { // find the closest point to the click location _myPane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out object nearestobject, out int index); // highlight the index HighlightIndex(index); // update the point value boxes curveIndex.Value = index; // get current mouse position lastMousePoint = GetMouseCoords(); // flag that we have the mouse down mouseDown = true; // return complete return(true); }
// Mouse Events for Moving Interval Lines ... private bool zgc_MouseDownEvent_1(ZedGraphControl sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && ModifierKeys.HasFlag(Keys.Control)) { GraphPane pane = zgc.GraphPane; object nearestObject; int index; pane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out nearestObject, out index); if (nearestObject != null && nearestObject.GetType() == typeof(LineItem)) { intervalLine = (LineItem)nearestObject; int hrmObjectIndex = zgraph.ConvertPointToHRMObjectIndex(intervalLine, HRMdata.Frequency); int tempValue = hrmObjectIndex; int oldDiff = int.MaxValue, newDiff = 0; for (int i = 0; i < interval.Count; i++) { for (int j = 0; j < interval[i].Count(); j++) { newDiff = hrmObjectIndex - interval[i][j]; if (newDiff < oldDiff && newDiff > 0) { intervalIndex1 = i; intervalIndex2 = j; oldDiff = newDiff; } } } mouseDragged = true; } } return(default(bool)); }