public void BringShapeToFront(Shape frontShape) { foreach (Shape shape in List) { shape.ZOrder++; } frontShape.ZOrder = 0; }
public void SendShapeToBack(Shape backShape) { int maxZOrder = 0; foreach (Shape shape in List) { if (shape.ZOrder > maxZOrder) maxZOrder = shape.ZOrder; } maxZOrder++; backShape.ZOrder = maxZOrder; }
public void Add(Shape shapeToAdd) { // Reorder the shapes so the new shape is on top. foreach (Shape shape in List) { shape.ZOrder++; } shapeToAdd.ZOrder = 0; List.Add(shapeToAdd); }
private void mnuNewShape_Click(object sender, System.EventArgs e) { // Create and configure the shape with some defaults. Shape newShape = new Shape(); newShape.Size = new Size(40, 40); newShape.ForeColor = Color.Coral; // Configure the appropriate shape depending on the menu option selected. if (sender == mnuRectangle) { newShape.Type = Shape.ShapeType.Rectangle; } else if (sender == mnuEllipse) { newShape.Type = Shape.ShapeType.Ellipse; } else if (sender == mnuTriangle) { newShape.Type = Shape.ShapeType.Triangle; } // To determine where to place the shape, you need to convert the // current screen-based mouse coordinates into relative form coordinates. newShape.Location = this.PointToClient(Control.MousePosition); // Attach a context menu to the shape. newShape.ContextMenuStrip = mnuSelectShape; // Connect the shape to all its event handlers. newShape.MouseDown += new MouseEventHandler(ctrl_MouseDown); newShape.MouseMove += new MouseEventHandler(ctrl_MouseMove); newShape.MouseUp += new MouseEventHandler(ctrl_MouseUp); // Add the shape to the form. this.Controls.Add(newShape); }
public void Remove(Shape shapeToRemove) { List.Remove(shapeToRemove); }
private void ClearSelectedShape() { if (currentShape != null) { currentShape.Selected = false; // Make sure the display is updated to reflect // newly de-selected shape. // Only use if NO double-buffering. Invalidate(currentShape.GetLargestPossibleRegion()); } currentShape = null; }