DashStyle DashStyle DashStyle DashStyle Enum


Specifies the style of dashed lines drawn with a Pen object.

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


Custom Custom Custom Custom 5

Specifies a user-defined custom dash style.

Dash Dash Dash Dash 1

Specifies a line consisting of dashes.

DashDot DashDot DashDot DashDot 3

Specifies a line consisting of a repeating pattern of dash-dot.

DashDotDot DashDotDot DashDotDot DashDotDot 4

Specifies a line consisting of a repeating pattern of dash-dot-dot.

Dot Dot Dot Dot 2

Specifies a line consisting of dots.

Solid Solid Solid Solid 0

Specifies a solid line.


The following code example demonstrates how to create a pen and set its DashStyle property using the DashStyle enumeration.

This example is designed to be used with Windows Forms. Create a form that contains a Button named Button3. 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


To define a custom DashStyle, set the DashPattern property of the Pen.

Applies to

See also