private void mnuNewShape_Click(object sender, System.EventArgs e) { // Create and configure the shape with some defaults. Shape newShape = null; // Configure the appropriate shape depending on the menu option selected. if (sender == mnuRectangle || sender == cmdRectangle) { newShape = new RectangleShape(); } else if (sender == mnuEllipse || sender == cmdEllipse) { newShape = new EllipseShape(); } else if (sender == mnuTriangle || sender == cmdTriangle) { newShape = new TriangleShape(); } else { throw new ApplicationException("Not a valid shape command."); } newShape.Size = new Size(40, 40); newShape.ForeColor = Color.Coral; if (sender is ToolStripButton) { newShape.Location = new Point(150, 100); } else { // To determine where to place the shape, you need to convert the // current screen-based mouse coordinates into relative form coordinates. newShape.Location = PointToClient(Control.MousePosition); } // Remove the last selected shape. ClearSelectedShape(); currentShape = newShape; currentShape.Selected = true; // Add the shape to the form and trigger a refresh. shapes.Add(newShape); Invalidate(newShape.GetLargestPossibleRegion()); }