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 表單。 處理表單的 Paint 事件,並 DrawCaps 從表單 Paint 的事件處理方法呼叫,傳遞 ePaintEventArgs


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+ 支援多種預設的上限樣式,並允許使用者自行定義上限樣式。 此類別用於建立自訂的上限樣式。

Note

在 .NET 6 和更新版本中,只有 Windows作系統才支援包含此類型的 System.Drawing.Common 套件。 跨平台應用程式使用此類會引發編譯時警告及執行時異常。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common。

建構函式

名稱 Description
CustomLineCap(GraphicsPath, GraphicsPath, LineCap, Single)

從指定的既有CustomLineCap列舉初始化類別的新實例LineCap,並包含指定的輪廓、填充與內嵌。

CustomLineCap(GraphicsPath, GraphicsPath, LineCap)

從指定的既有CustomLineCap枚舉初始化該類別的新實例LineCap,並以指定的輪廓與填充方式。

CustomLineCap(GraphicsPath, GraphicsPath)

初始化一個新實例 CustomLineCap ,並以指定的輪廓與填充值。

屬性

名稱 Description
BaseCap

取得或設定 LineCap 此定義 CustomLineCap 所依據的枚舉。

BaseInset

用來設定帽與線之間的距離。

StrokeJoin

取得或設定 LineJoin 決定組成此 CustomLineCap 物件的線如何連接的枚舉。

WidthScale

取得或設定該類別物件相對於物件寬CustomLineCap度的縮放Pen幅度。

方法

名稱 Description
Clone()

會建立一個完全相同的複製品。CustomLineCap

CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Dispose()

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

Dispose(Boolean)

釋放 未管理的資源, CustomLineCap 並可選擇性地釋放受管理資源。

Equals(Object)

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

(繼承來源 Object)
Finalize()

允許 嘗試 CustomLineCap 釋放資源並執行其他清理作業,直到被 CustomLineCap 垃圾回收回收。

GetHashCode()

做為預設哈希函式。

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

擷取控制這個實例存留期原則的目前存留期服務物件。

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

取得用來組成這個自訂帽的起點和結尾線的帽。

GetType()

取得目前實例的 Type

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

取得存留期服務物件,以控制這個實例的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 對象的淺層複本。

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

設定用於組成這個自訂帽的起訖線的電位。

ToString()

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

(繼承來源 Object)

適用於