Export (0) Print
Expand All

GraphicsPath.Clone Method

Creates an exact copy of this path.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public Object Clone()

Return Value

Type: System.Object
The GraphicsPath this method creates, cast as an object.

Implements

ICloneable.Clone()

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a path.

  • Adds several figures to the path.

  • Draws the path to the screen.

  • Clones a copy of that path.

  • Draws the new path to the screen.

Notice that the call the Clone method must be cast as a GraphicsPath.

private void CloneExample(PaintEventArgs e)
{

    // Set several markers in a path.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddEllipse(0, 0, 100, 200);
    myPath.AddLine(new Point(100, 100), new Point(200, 100));
    Rectangle rect = new Rectangle(200, 0, 100, 200);
    myPath.AddRectangle(rect);
    myPath.AddLine(new Point(250, 200), new Point(250, 300));

    // Draw the path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);

    // Clone a copy of myPath.
    GraphicsPath myPath2 = (GraphicsPath)myPath.Clone();

    // Draw the path to the screen.
    Pen myPen2 = new Pen(Color.Red, 4);
    e.Graphics.DrawPath(myPen2, myPath2);
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft