Pen.DashCap 屬性

定義

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

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

屬性值

其中一個 DashCap 值,表示帽緣樣式,用於組成以這個 Pen 所繪製之短折線的虛線開端和末端。

例外狀況

指定的值不是 DashCap 的成員。

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

範例

下列程式碼範例示範如何建立 Pen 和 設定 、 DashPatternSmoothingMode 屬性的效果 DashCap

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

private:
   void ShowPensAndSmoothingMode( PaintEventArgs^ e )
   {
      // Set the SmoothingMode property to smooth the line.
      e->Graphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::AntiAlias;

      // Create a new Pen object.
      Pen^ greenPen = gcnew Pen( Color::Green );

      // Set the width to 6.
      greenPen->Width = 6.0F;

      // Set the DashCap to round.
      greenPen->DashCap = System::Drawing::Drawing2D::DashCap::Round;

      // Create a custom dash pattern.
      array<Single>^temp0 = {4.0F,2.0F,1.0F,3.0F};
      greenPen->DashPattern = temp0;

      // Draw a line.
      e->Graphics->DrawLine( greenPen, 20.0F, 20.0F, 100.0F, 240.0F );

      // Change the SmoothingMode to none.
      e->Graphics->SmoothingMode = System::Drawing::Drawing2D::SmoothingMode::None;

      // Draw another line.
      e->Graphics->DrawLine( greenPen, 100.0F, 240.0F, 160.0F, 20.0F );

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

    // Set the SmoothingMode property to smooth the line.
    e.Graphics.SmoothingMode = 
        System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

    // Create a new Pen object.
    Pen greenPen = new Pen(Color.Green);

    // Set the width to 6.
    greenPen.Width = 6.0F;

    // Set the DashCap to round.
    greenPen.DashCap = System.Drawing.Drawing2D.DashCap.Round;

    // Create a custom dash pattern.
    greenPen.DashPattern = new float[]{4.0F, 2.0F, 1.0F, 3.0F};

    // Draw a line.
    e.Graphics.DrawLine(greenPen, 20.0F, 20.0F, 100.0F, 240.0F);

    // Change the SmoothingMode to none.
    e.Graphics.SmoothingMode = 
        System.Drawing.Drawing2D.SmoothingMode.None;

    // Draw another line.
    e.Graphics.DrawLine(greenPen, 100.0F, 240.0F, 160.0F, 20.0F);

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

    ' Set the SmoothingMode property to smooth the line.
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

    ' Create a new Pen object.
    Dim greenPen As New Pen(Color.Green)

    ' Set the width to 6.
    greenPen.Width = 6.0F

    ' Set the DashCap to round.
    greenPen.DashCap = Drawing2D.DashCap.Round

    ' Create a custom dash pattern.
    greenPen.DashPattern = New Single() {4.0F, 2.0F, 1.0F, 3.0F}

    ' Draw a line.
    e.Graphics.DrawLine(greenPen, 20.0F, 20.0F, 100.0F, 240.0F)

    ' Change the SmoothingMode to none.
    e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.None

    ' Draw another line.
    e.Graphics.DrawLine(greenPen, 100.0F, 240.0F, 160.0F, 20.0F)

    ' Dispose of the custom pen.
    greenPen.Dispose()
End Sub

備註

如果 的 Alignment 屬性設定為 , Pen 請勿將此屬性 Triangle 設定為 Inset

適用於