Pen.DashCap 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定帽緣樣式,用於組成以這個 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 的成員。
範例
下列程式代碼範例示範如何建立 Pen 和 設定 DashCap、 DashPattern和 SmoothingMode 屬性的效果。
此範例的設計目的是要與 Windows Forms 搭配使用。 將程式代碼貼到表單中,並在處理表單的事件時呼叫 ShowPensAndSmoothingMode
方法,並e
傳遞為 PaintEventArgs。Paint
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
備註
如果 的 屬性Triangle設定為 ,Pen請勿將此屬性設定為 Inset。Alignment