Pen.Clone 方法

定义

创建此 Pen的确切副本。

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

返回

可强制转换为 PenObject

实现

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 创建 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 );
   }
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);
}
Public Sub Clone_Example(ByVal e As PaintEventArgs)

    ' Create a Pen object.
    Dim myPen As New Pen(Color.Black, 5)

    ' Clone myPen.
    Dim clonePen As Pen = CType(myPen.Clone(), Pen)

    ' Draw a line with clonePen.
    e.Graphics.DrawLine(clonePen, 0, 0, 100, 100)
End Sub

适用于