Pen.DashPattern 속성

정의

사용자 정의 대시와 공백의 배열을 가져오거나 설정합니다.

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 클래스에서 반환된 것과 같은 변경 불가능한 PenPens 속성을 설정한 경우

예제

다음 코드 예제에서는 설정의 효과 보여 줍니다는 DashCap, DashPattern, 및 SmoothingMode 속성입니다.

이 예제는 Windows Forms 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 Paint 이벤트를 처리할 때 메서드를 호출 ShowPensAndSmoothingMode 하여 로 PaintEventArgs전달 e 합니다.

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 값을 할당하면 이 PenCustom속성이 DashStyle 로 설정됩니다.

배열의 dashArray 요소는 대시 패턴에서 각 대시 및 공간의 길이를 설정합니다. 첫 번째 요소는 대시의 길이를 설정하고, 두 번째 요소는 공간의 길이를 설정하고, 세 번째 요소는 대시의 길이를 설정하는 등입니다. 따라서 각 요소는 0이 아닌 양수여야 합니다.

대시 패턴의 각 대시 및 공간 길이는 배열의 요소 값과 너비의 곱입니다 Pen.

적용 대상