private void drawingArea_MouseClick(object sender, MouseEventArgs e) { PointF dot = new PointF(e.Location.X, e.Location.Y); dot = graphEditor.TranslateToLocal(dot, drawingArea.DisplayRectangle); int?id = graphEditor.TryGetNode(dot, drawingArea.ClientRectangle); switch (currentMode) { case Mode.AddMoveNode: if (id != null) { return; } graphEditor.AddNode(dot.X, dot.Y); drawingArea.Invalidate(); break; case Mode.AddEdge: if (id == null) { return; } if (lastClicked != null) { graphEditor.AddEdge((int)lastClicked, (int)id, (int)weightNumeric.Value); graphEditor.AddEdge((int)id, (int)lastClicked, (int)weightNumeric.Value); graphEditor.ChangeNodeColor((int)lastClicked, Color.White); lastClicked = null; drawingArea.Invalidate(); return; } graphEditor.ChangeNodeColor((int)id, Color.Yellow); lastClicked = id; drawingArea.Invalidate(); break; case Mode.RemoveEdge: if (id == null) { return; } if (lastClicked == null) { lastClicked = id; graphEditor.ChangeNodeColor((int)id, Color.Red); drawingArea.Invalidate(); return; } graphEditor.RemoveEdge((int)lastClicked, (int)id); graphEditor.ChangeNodeColor((int)lastClicked, Color.White); lastClicked = null; drawingArea.Invalidate(); break; } }