CustomLineCap CustomLineCap CustomLineCap CustomLineCap Class

定义

封装自定义的用户定义的线帽。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
继承
派生
实现

示例

下面的示例演示如何使用 CustomLineCap 类。The following example demonstrates how to use the CustomLineCap class. 若要运行此示例,请将代码粘贴到 Windows 窗体中。To run this example paste, the code into a Windows Form. 处理窗Paint体的事件,并DrawCaps从窗体的Paint事件处理方法调用,并ePaintEventArgs作为传递。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

注解

线条帽用于线条的开头和结尾,或由 gdi + Pen对象绘制的曲线。Line caps are used at the beginnings and ends of lines or curves drawn by GDI+ Pen objects. GDI + 支持多个预定义的线帽样式,并且还允许用户定义自己的 cap 样式。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.

构造函数

CustomLineCap(GraphicsPath, GraphicsPath) CustomLineCap(GraphicsPath, GraphicsPath) CustomLineCap(GraphicsPath, GraphicsPath) CustomLineCap(GraphicsPath, GraphicsPath)

使用指定的轮廓和填充初始化 CustomLineCap 类的新实例。Initializes a new instance of the CustomLineCap class with the specified outline and fill.

CustomLineCap(GraphicsPath, GraphicsPath, LineCap) CustomLineCap(GraphicsPath, GraphicsPath, LineCap) CustomLineCap(GraphicsPath, GraphicsPath, LineCap) CustomLineCap(GraphicsPath, GraphicsPath, LineCap)

通过指定的轮廓和填充从指定的现有 CustomLineCap 枚举初始化 LineCap 类的新实例。Initializes a new instance of the CustomLineCap class from the specified existing LineCap enumeration with the specified outline and fill.

CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single) CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single) CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single) CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single)

通过指定的轮廓、填充和嵌入从指定的现有 CustomLineCap 枚举初始化 LineCap 类的新实例。Initializes a new instance of the CustomLineCap class from the specified existing LineCap enumeration with the specified outline, fill, and inset.

属性

BaseCap BaseCap BaseCap BaseCap

获取或设置该 LineCap 所基于的 CustomLineCap 枚举。Gets or sets the LineCap enumeration on which this CustomLineCap is based.

BaseInset BaseInset BaseInset BaseInset

获取或设置线帽和直线之间的距离。Gets or sets the distance between the cap and the line.

StrokeJoin StrokeJoin StrokeJoin StrokeJoin

获取或设置 LineJoin 枚举,该枚举确定如何联接构成此 CustomLineCap 对象的直线。Gets or sets the LineJoin enumeration that determines how lines that compose this CustomLineCap object are joined.

WidthScale WidthScale WidthScale WidthScale

获取或设置相对于 CustomLineCap 对象的宽度此 Pen 类对象的缩放量。Gets or sets the amount by which to scale this CustomLineCap Class object with respect to the width of the Pen object.

方法

Clone() Clone() Clone() Clone()

创建此 CustomLineCap 的一个精确副本。Creates an exact copy of this CustomLineCap.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) 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() Dispose() Dispose() Dispose()

释放由此 CustomLineCap 对象使用的所有资源。Releases all resources used by this CustomLineCap object.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 CustomLineCap 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the CustomLineCap and optionally releases the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

允许 CustomLineCap 在"垃圾回收"回收 CustomLineCap 之前尝试释放资源并执行其他清理操作。Allows an CustomLineCap to attempt to free resources and perform other cleanup operations before the CustomLineCap is reclaimed by garbage collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetStrokeCaps(LineCap, LineCap) GetStrokeCaps(LineCap, LineCap) GetStrokeCaps(LineCap, LineCap) GetStrokeCaps(LineCap, LineCap)

获取用于构成此自定义线帽的起始直线和结束直线的线帽。Gets the caps used to start and end lines that make up this custom cap.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
SetStrokeCaps(LineCap, LineCap) SetStrokeCaps(LineCap, LineCap) SetStrokeCaps(LineCap, LineCap) SetStrokeCaps(LineCap, LineCap)

设置用于构成此自定义线帽的起始直线和结束直线的线帽。Sets the caps used to start and end lines that make up this custom cap.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于