GraphicsPath.Clone 메서드

정의

이 경로와 정확하게 일치하는 복사본을 만듭니다.

public:
 virtual System::Object ^ Clone();
public object Clone ();
abstract member Clone : unit -> obj
override this.Clone : unit -> obj
Public Function Clone () As Object

반환

Object

이 메서드가 개체로 만들어 캐스팅하는 GraphicsPath를 반환합니다.

구현

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 이벤트 개체가 OnPaint 필요합니다 PaintEventArgs e. 코드는 다음 작업을 수행합니다.

  • 경로를 만듭니다.

  • 경로에 여러 그림을 추가합니다.

  • 화면의 경로를 그립니다.

  • 해당 경로의 복사본을 복제합니다.

  • 화면의 새 경로를 그립니다.

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 = 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 );
   }
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);
}
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

적용 대상