Pen::Clone Method ()

 

Creates an exact copy of this Pen.

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

public:
virtual Object^ Clone() sealed

Return Value

Type: System::Object^

An Object that can be cast to a Pen.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a Pen.

  • Creates a copy of that pen.

  • Draws a line to the screen, using the copy of the pen.

public:
   void Clone_Example( PaintEventArgs^ e )
   {

      // Create a Pen object.
      Pen^ myPen = gcnew Pen( Color::Black,5.0f );

      // Clone myPen.
      Pen^ clonePen = dynamic_cast<Pen^>(myPen->Clone());

      // Draw a line with clonePen.
      e->Graphics->DrawLine( clonePen, 0, 0, 100, 100 );
   }

.NET Framework
Available since 1.1
Return to top
Show: