DashStyle Enum


指定用 Pen 对象绘制的虚线的样式。Specifies the style of dashed lines drawn with a Pen object.

public enum class DashStyle
public enum DashStyle
type DashStyle = 
Public Enum DashStyle


Custom 5

指定用户定义的自定义划线段样式。Specifies a user-defined custom dash style.

Dash 1

指定由划线段组成的直线。Specifies a line consisting of dashes.

DashDot 3

指定由重复的划线点图案构成的直线。Specifies a line consisting of a repeating pattern of dash-dot.

DashDotDot 4

指定由重复的划线点点图案构成的直线。Specifies a line consisting of a repeating pattern of dash-dot-dot.

Dot 2

指定由点构成的直线。Specifies a line consisting of dots.

Solid 0

指定实线。Specifies a solid line.


下面的代码示例演示如何使用 DashStyle 枚举来创建笔并设置其 DashStyle 属性。The following code example demonstrates how to create a pen and set its DashStyle property using the DashStyle enumeration.

此示例旨在与 Windows 窗体一起使用。This example is designed to be used with Windows Forms. 创建一个包含名为 Button3Button 的窗体。Create a form that contains a Button named Button3. 将代码粘贴到窗体中,并将 Button3_Click 方法与按钮的 Click 事件关联。Paste the code into the form and associate the Button3_Click method with the button's Click event.

   void Button3_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
      Graphics^ buttonGraphics = Button3->CreateGraphics();
      Pen^ myPen = gcnew Pen( Color::ForestGreen,4.0F );
      myPen->DashStyle = System::Drawing::Drawing2D::DashStyle::DashDotDot;
      Rectangle theRectangle = Button3->ClientRectangle;
      theRectangle.Inflate(  -2, -2 );
      buttonGraphics->DrawRectangle( myPen, theRectangle );
      delete buttonGraphics;
      delete myPen;
private void Button3_Click(System.Object sender, System.EventArgs e)

    Graphics buttonGraphics = Button3.CreateGraphics();
    Pen myPen = new Pen(Color.ForestGreen, 4.0F);
    myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;

    Rectangle theRectangle = Button3.ClientRectangle;
    theRectangle.Inflate(-2, -2);
    buttonGraphics.DrawRectangle(myPen, theRectangle);
Private Sub Button3_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button3.Click

    Dim buttonGraphics As Graphics = Button3.CreateGraphics()
    Dim myPen As Pen = New Pen(Color.ForestGreen, 4.0F)
    myPen.DashStyle = Drawing2D.DashStyle.DashDotDot

    Dim theRectangle As Rectangle = Button3.ClientRectangle
    theRectangle.Inflate(-2, -2)
    buttonGraphics.DrawRectangle(myPen, theRectangle)
End Sub


若要定义自定义 DashStyle,请设置 PenDashPattern 属性。To define a custom DashStyle, set the DashPattern property of the Pen.

Applies to

See also