GraphicsPath.Clone Method
Creates an exact copy of this path.

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

Syntax

Visual Basic (Declaration)
Public Function Clone As Object
Visual Basic (Usage)
Dim instance As GraphicsPath
Dim returnValue As Object

returnValue = instance.Clone
C#
public Object Clone ()
C++
public:
virtual Object^ Clone () sealed
J#
public final Object Clone ()
JScript
public final function Clone () : Object
XAML
Not applicable.

Return Value

The GraphicsPath this method creates, cast as an object.
Example

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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.

Visual Basic
Public Sub CloneExample(ByVal e As PaintEventArgs)

    ' Set several markers in a path.
    Dim myPath As New GraphicsPath
    myPath.AddEllipse(0, 0, 100, 200)
    myPath.AddLine(New Point(100, 100), New Point(200, 100))
    Dim rect As 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.
    Dim myPen As New Pen(Color.Black, 2)
    e.Graphics.DrawPath(myPen, myPath)

    ' Clone a copy of myPath.
    Dim myPath2 As GraphicsPath = CType(myPath.Clone(), GraphicsPath)

    ' Draw the path to the screen.
    Dim myPen2 As New Pen(Color.Red, 4)
    e.Graphics.DrawPath(myPen2, myPath2)
End Sub
C#
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);
}
C++
private:
   void CloneExample( PaintEventArgs^ e )
   {
      // Set several markers in a path.
      GraphicsPath^ myPath = gcnew GraphicsPath;
      myPath->AddEllipse( 0, 0, 100, 200 );
      myPath->AddLine( Point(100,100), Point(200,100) );
      Rectangle rect = Rectangle(200,0,100,200);
      myPath->AddRectangle( rect );
      myPath->AddLine( Point(250,200), Point(250,300) );

      // Draw the path to the screen.
      Pen^ myPen = gcnew Pen( Color::Black,2.0f );
      e->Graphics->DrawPath( myPen, myPath );

      // Clone a copy of myPath.
      GraphicsPath^ myPath2 = dynamic_cast<GraphicsPath^>(myPath->Clone());

      // Draw the path to the screen.
      Pen^ myPen2 = gcnew Pen( Color::Red,4.0f );
      e->Graphics->DrawPath( myPen2, myPath2 );
   }
J#
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.get_Black(), 2);

    e.get_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.get_Red(), 4);

    e.get_Graphics().DrawPath(myPen2, myPath2);
} //CloneExample
Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

Tags :


Community Content

CChalom
Visual FoxPro code:

Converted code from .NET to GdiPlusX VFP-X Foundation Classes
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

 _SCREEN.AddProperty("System", NEWOBJECT("xfcSystem", LOCFILE("system.vcx","vcx"))) 
 WITH _SCREEN.System.Drawing
 * Retrieve the graphics object.
* Initialize the graphics object to be able to draw in the _screen
LOCAL loScreenGfx AS xfcGraphics
loScreenGfx = .Graphics.FromHwnd(_Screen.HWnd)
 * Set several markers in a path.
LOCAL loMyPath as xfcGraphicsPath
loMyPath = .Drawing2D.GraphicsPath.New()
 loMyPath.AddEllipse(0, 0, 100, 200)
loMyPath.AddLine(.Point.New(100, 100), .Point.New(200, 100))
 LOCAL loRect as xfcRectangle
loRect = .Rectangle.New(200, 0, 100, 200)
loMyPath.AddRectangle(loRect)
loMyPath.AddLine(.Point.New(250, 200), .Point.New(250, 300))
 * Draw the path to the screen.
LOCAL loMyPen as xfcPen
loMyPen = .Pen.New(.Color.Black, 2)
 loScreenGfx.DrawPath(loMyPen, loMyPath)
 * Clone a copy of myPath.
LOCAL loMyPath2 AS xfcGraphicsPath
loMyPath2 = loMyPath.Clone()
 * Draw the path to the screen.
LOCAL loMyPen2 as xfcPen
loMyPen2 = .Pen.New(.Color.Red, 4)
 loScreenGfx.DrawPath(loMyPen2, loMyPath2)
 ENDWITH 
Tags :

Page view tracker