CustomLineCap.Clone Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates an exact copy of this CustomLineCap.

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

public object Clone()

Return Value

Type: System.Object

The CustomLineCap this method creates, cast as an object.

The following example is designed for use with Windows Forms, and it requires PaintEventArgse, an Paint event object. The code performs the following actions:

  • Creates a custom line cap by using the GraphicsPath object.

  • Creates a CustomLineCap object, firstCap,using the GraphicsPath object just created.

  • Creates a clone of firstCap by using the Clone method.

  • Sets up the CustomStartCap and CustomEndCap properties of the Pen object, and uses that pen to draw a line and the custom caps to the screen.

private void CloneExample(PaintEventArgs e)
 // Create a Path and add two lines to it,
 // forming a custom line cap.
 Point[] points =
 new Point(-5, -5),
 new Point(0, 0),
 new Point(5, -5)
 GraphicsPath capPath = new GraphicsPath();
 // Create a CustomLineCap object.
 CustomLineCap firstCap = new CustomLineCap(null, capPath);
 // Create a copy of firstCap.
 CustomLineCap secondCap = (CustomLineCap)firstCap.Clone();
 // Create a Pen object.
 Pen pen = new Pen(Color.Black, 3.0f);
 // Set up the line.
 Point point1 = new Point(20, 20);
 Point point2 = new Point(100, 100);
 // Set up the caps.
 pen.CustomStartCap = firstCap;
 pen.CustomEndCap = secondCap;
 // Draw the line and caps to the screen.
 e.Graphics.DrawLine(pen, point1, point2);

.NET Framework
Available since 1.1
Return to top