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 窗体 一起使用。 将代码粘贴到窗体中,并在处理窗体的 Paint 事件时调用 ShowPensAndSmoothingMode
方法,作为 e
PaintEventArgs传递。
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 则不要将 Alignment 此属性设置为 Inset。