private void pictureBox1_Click(object sender, EventArgs e) { // Downcast eventargs MouseEventArgs mouseClick = (MouseEventArgs)e; // Route mouse event based on current application status switch (appStatus) { case ADD_RECT_START: // Create first point of new obstacle lastPoint = getGridPoint(mouseClick); appStatus = ADD_RECT_END; toolStripStatusLabel1.Text = "Click to finish obstacle"; break; case ADD_RECT_END: // Finish new obstacle Point p = getGridPoint(mouseClick); int x = p.X; int y = p.Y; int width, height, startX, startY; if (x > lastPoint.X) { width = x - lastPoint.X; startX = lastPoint.X; } else { width = lastPoint.X - x; startX = x; } if (y > lastPoint.Y) { height = y - lastPoint.Y; startY = lastPoint.Y; } else { height = lastPoint.Y - y; startY = y; } Point startPoint = new Point(startX, startY); Rect rect = new Rect(startPoint, width, height); rects.Enqueue(rect); appStatus = IDLE; toolStripStatusLabel1.Text = defaultStatus; break; case ADD_START: // Add path start point if (StartPoint == null) { StartPoint = new MapPoint(getGridPoint(mouseClick), false, Color.Blue); points.Add(StartPoint); appStatus = IDLE; toolStripStatusLabel1.Text = defaultStatus; } break; case ADD_END: // Add path end point if (EndPoint == null) { EndPoint = new MapPoint(getGridPoint(mouseClick), false, Color.Red); points.Add(EndPoint); appStatus = IDLE; toolStripStatusLabel1.Text = defaultStatus; } break; } // Redraw the pictureBox pictureBox1.Invalidate(); }
/// <summary> /// Draws a single MapPoint point in Graphics component g. /// </summary> /// <param name="point"></param> /// <param name="g"></param> private void DrawMapPoint(MapPoint point, Graphics g) { SolidBrush pointBrush = new SolidBrush(point.MyColor); Rectangle rect = new Rectangle(point.X - 5, point.Y - 5, 10, 10); g.FillEllipse(pointBrush, rect); }