CustomLineCap.SetStrokeCaps(LineCap, LineCap) 方法

定義

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

C#
public void SetStrokeCaps (System.Drawing.Drawing2D.LineCap startCap, System.Drawing.Drawing2D.LineCap endCap);

參數

startCap
LineCap

用於這個端點中線條開端的 LineCap 列舉型別。

endCap
LineCap

用於這個端點中線條末端的 LineCap 列舉型別。

範例

下列範例示範如何使用 SetStrokeCaps 方法。 若要執行此範例,請將程式代碼貼到 Windows Form 中。 處理表單的事件Paint,並從表單的事件Paint處理方法呼叫 DrawCaps ,並e傳遞為 PaintEventArgs

C#

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 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9