CustomLineCap 類別

定義

封裝自訂的使用者定義線條端點。

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
衍生
實作

範例

下列範例將示範如何使用 CustomLineCap 類別。 若要執行此範例,請將程式碼貼到 Windows Form 中。 處理表單的事件 Paint ,並從表單的事件 Paint 處理方法呼叫 DrawCaps ,並 e 傳遞為 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 物件所繪製線條或曲線的開頭和結尾。 GDI+ 支援數個預先定義的大寫樣式,也允許使用者定義自己的大寫樣式。 這個類別是用來建立自訂大寫樣式。

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時期警告和執行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

建構函式

CustomLineCap(GraphicsPath, GraphicsPath)

使用指定的外框和填滿,初始化 CustomLineCap 類別的新執行個體。

CustomLineCap(GraphicsPath, GraphicsPath, LineCap)

使用指定的外框和填滿,從指定的現有 CustomLineCap 列舉型別初始化 LineCap 類別的新執行個體。

CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single)

使用指定的外框、填滿和內凹,從指定的現有 CustomLineCap 列舉型別初始化 LineCap 類別的新執行個體。

屬性

BaseCap

取得或設定這個 LineCap 所根據的 CustomLineCap 列舉型別。

BaseInset

取得或設定端點和線條之間的距離。

StrokeJoin

取得或設定判斷組成這個 LineJoin 物件的線條如何聯結 (Join) 的 CustomLineCap 列舉型別。

WidthScale

取得或設定縮放與 CustomLineCap 物件寬度相關的這個 Pen 類別物件的數量。

方法

Clone()

建立這個 CustomLineCap 的完全相同複本。

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放這個 CustomLineCap 物件使用的所有資源。

Dispose(Boolean)

釋放 CustomLineCap 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

在記憶體回收 (GC) 回收 CustomLineCap 前,允許 CustomLineCap 嘗試釋放資源並執行其他清除作業。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetStrokeCaps(LineCap, LineCap)

取得用來起始和結束組成這個自訂端點線條的端點。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
SetStrokeCaps(LineCap, LineCap)

設定用來起始和結束組成這個自訂端點線條的端點。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於