Pen.DashPattern 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定自訂虛線和間距的陣列。
public:
property cli::array <float> ^ DashPattern { cli::array <float> ^ get(); void set(cli::array <float> ^ value); };
public float[] DashPattern { get; set; }
member this.DashPattern : single[] with get, set
Public Property DashPattern As Single()
屬性值
Single[]
實數陣列,指定短折線中交替的虛線和間距的長度。
例外狀況
DashPattern 屬性設定於不可變動的 Pen 上,例如 Pens 類別傳回的項目。
範例
下列程式代碼範例示範設定 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
備註
將這個 屬性以外的null
值指派給 ,會將這個 Pen 屬性設定DashStyle為 Custom。
陣列中的 dashArray
元素會設定虛線圖樣中每個虛線和空格的長度。 第一個項目會設定虛線的長度、第二個元素設定空格的長度、第三個元素設定虛線的長度等等。 因此,每個元素都應該是非零正數。
虛線圖樣中每個虛線和空格的長度是 陣列中專案值的乘積,以及的 Pen寬度。