Επεξεργασία

Κοινή χρήση μέσω


CustomLineCap Class

Definition

Encapsulates a custom user-defined line cap.

public ref class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable
public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable
type CustomLineCap = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
Public Class CustomLineCap
Inherits MarshalByRefObject
Implements ICloneable, IDisposable
Inheritance
CustomLineCap
Derived
Implements

Examples

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);
}
Protected Sub DrawCaps(ByVal e As PaintEventArgs)
    Dim hPath As 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.
    Dim HookCap As New CustomLineCap(Nothing, 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.
    Dim customCapPen As 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.
    Dim capPen As New Pen(Color.Red, 10)
    Dim startCap As LineCap
    Dim endCap As LineCap
    HookCap.GetStrokeCaps(startCap, endCap)
    capPen.StartCap = startCap
    capPen.EndCap = endCap

    ' Create a line to draw.
    Dim points As Point() = {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)

End Sub

Remarks

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.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

Constructors

CustomLineCap(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.

CustomLineCap(GraphicsPath, GraphicsPath, LineCap)

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

CustomLineCap(GraphicsPath, GraphicsPath)

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

Properties

BaseCap

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

BaseInset

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

StrokeJoin

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

WidthScale

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

Methods

Clone()

Creates an exact copy of this CustomLineCap.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by this CustomLineCap object.

Dispose(Boolean)

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()

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

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetStrokeCaps(LineCap, LineCap)

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

GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
SetStrokeCaps(LineCap, LineCap)

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

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to