Pen.EndCap 屬性

定義

取得或設定帽緣樣式,用於以這個 Pen 所繪製的直線末端。

public:
 property System::Drawing::Drawing2D::LineCap EndCap { System::Drawing::Drawing2D::LineCap get(); void set(System::Drawing::Drawing2D::LineCap value); };
public System.Drawing.Drawing2D.LineCap EndCap { get; set; }
member this.EndCap : System.Drawing.Drawing2D.LineCap with get, set
Public Property EndCap As LineCap

屬性值

其中一個 LineCap 值,表示帽緣樣式,用於以這個 Pen 所繪製的直線末端。

例外狀況

指定的值不是 LineCap 的成員。

EndCap 屬性設定於不可變動的 Pen 上,例如 Pens 類別傳回的項目。

範例

下列程式碼範例示範在 上 Pen 設定 StartCapEndCap 屬性的效果。

此範例的設計目的是要與Windows Forms搭配使用。 將程式碼貼到表單中,並在處理表單的事件 Paint 時呼叫 ShowStartAndEndCaps 方法,並傳遞 ePaintEventArgs

private:
   void ShowStartAndEndCaps( PaintEventArgs^ e )
   {
      // Create a new custom pen.
      Pen^ redPen = gcnew Pen( Brushes::Red,6.0F );

      // Set the StartCap property.
      redPen->StartCap = System::Drawing::Drawing2D::LineCap::RoundAnchor;

      // Set the EndCap property.
      redPen->EndCap = System::Drawing::Drawing2D::LineCap::ArrowAnchor;

      // Draw a line.
      e->Graphics->DrawLine( redPen, 40.0F, 40.0F, 145.0F, 185.0F );

      // Dispose of the custom pen.
      delete redPen;
   }
private void ShowStartAndEndCaps(PaintEventArgs e)
{

    // Create a new custom pen.
    Pen redPen = new Pen(Brushes.Red, 6.0F);

    // Set the StartCap property.
    redPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;

    // Set the EndCap property.
    redPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;

    // Draw a line.
    e.Graphics.DrawLine(redPen, 40.0F, 40.0F, 145.0F, 185.0F);

    // Dispose of the custom pen.
    redPen.Dispose();
}
Private Sub ShowStartAndEndCaps(ByVal e As PaintEventArgs)

    ' Create a new custom pen.
    Dim redPen As New Pen(Brushes.Red, 6.0F)

    ' Set the StartCap property.
    redPen.StartCap = Drawing2D.LineCap.RoundAnchor

    ' Set the EndCap property.
    redPen.EndCap = Drawing2D.LineCap.ArrowAnchor

    ' Draw a line.
    e.Graphics.DrawLine(redPen, 40.0F, 40.0F, 145.0F, 185.0F)

    ' Dispose of the custom pen.
    redPen.Dispose()

End Sub

適用於