Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CustomLineCap Class


Encapsulates a custom user-defined line cap.

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

public class CustomLineCap : MarshalByRefObject, ICloneable, 

System_CAPS_pubmethodCustomLineCap(GraphicsPath, GraphicsPath)

Initializes a new instance of the CustomLineCap class with the specified outline and fill.

System_CAPS_pubmethodCustomLineCap(GraphicsPath, GraphicsPath, LineCap)

Initializes a new instance of the CustomLineCap class from the specified existing LineCap enumeration with the specified outline and fill.

System_CAPS_pubmethodCustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single)

Initializes a new instance of the CustomLineCap class from the specified existing LineCap enumeration with the specified outline, fill, and inset.


Gets or sets the LineCap enumeration on which this CustomLineCap is based.


Gets or sets the distance between the cap and the line.


Gets or sets the LineJoin enumeration that determines how lines that compose this CustomLineCap object are joined.


Gets or sets the amount by which to scale this CustomLineCap Class object with respect to the width of the Pen object.


Creates an exact copy of this CustomLineCap.


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)


Releases all resources used by this CustomLineCap object.


Releases the unmanaged resources used by the CustomLineCap and optionally releases the managed resources.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an CustomLineCap to attempt to free resources and perform other cleanup operations before the CustomLineCap is reclaimed by garbage collection.(Overrides Object.Finalize().)


Serves as the default hash function. (Inherited from Object.)


Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetStrokeCaps(LineCap, LineCap)

Gets the caps used to start and end lines that make up this custom cap.


Gets the Type of the current instance.(Inherited from Object.)


Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodSetStrokeCaps(LineCap, LineCap)

Sets the caps used to start and end lines that make up this custom cap.


Returns a string that represents the current object.(Inherited from Object.)

Line caps are used at the beginnings and ends of lines or curves drawn by GDI+ Pen objects. GDI+ supports several predefined cap styles, and also allows users to define their own cap styles. This class is used to create custom cap styles.

The following example demonstrates how to use the CustomLineCap class. To run this example paste, the code into a Windows Form. Handle the form's Paint event and call DrawCaps from the form's Paint event-handling method, passing e as PaintEventArgs.

protected void DrawCaps(PaintEventArgs e)
    GraphicsPath hPath = new GraphicsPath();

    // Create the outline for our custom end cap.
    hPath.AddLine(new Point(0, 0), new Point(0, 5));
    hPath.AddLine(new Point(0, 5), new Point(5, 1));
    hPath.AddLine(new Point(5, 1), new Point(3, 1));

    // Construct the hook-shaped end cap.
    CustomLineCap HookCap = new CustomLineCap(null, hPath);

    // Set the start cap and end cap of the HookCap to be rounded.
    HookCap.SetStrokeCaps(LineCap.Round, LineCap.Round);

    // Create a pen and set end custom start and end
    // caps to the hook cap.
    Pen customCapPen = new Pen(Color.Black, 5);
    customCapPen.CustomStartCap = HookCap;
    customCapPen.CustomEndCap = HookCap;

    // Create a second pen using the start and end caps from
    // the hook cap.
    Pen capPen = new Pen(Color.Red, 10);
    LineCap startCap;
    LineCap endCap;
    HookCap.GetStrokeCaps(out startCap, out endCap);
    capPen.StartCap = startCap;
    capPen.EndCap = endCap;

    // Create a line to draw.
    Point[] points = { new Point(100, 100), new Point(200, 50), 
        new Point(250, 300) };

    // Draw the lines.
    e.Graphics.DrawLines(capPen, points);
    e.Graphics.DrawLines(customCapPen, points);


.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft