コード例 #1
0
 public void BringShapeToFront(Shape frontShape)
 {
     foreach (Shape shape in List)
     {
         shape.ZOrder++;
     }
     frontShape.ZOrder = 0;
 }
コード例 #2
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;
 }
コード例 #3
0
 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);
 }
コード例 #4
0
		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);
		}
コード例 #5
0
 public void Remove(Shape shapeToRemove)
 {
     List.Remove(shapeToRemove);
 }
コード例 #6
0
        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;
        }