Lezen in het Engels Bewerken

Delen via


Pen.Clone Method

Definition

Creates an exact copy of this Pen.

public object Clone ();

Returns

An Object that can be cast to a Pen.

Implements

Examples

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, 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 = new Pen(Color.Black, 5);
             
    // Clone myPen.
    Pen clonePen = (Pen)myPen.Clone();
             
    // Draw a line with clonePen.
    e.Graphics.DrawLine(clonePen, 0, 0, 100, 100);
}

Applies to

Product Versies
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9