Pen.DashPattern Pen.DashPattern Pen.DashPattern Pen.DashPattern Property

정의

사용자 정의 대시와 공백의 배열을 가져오거나 설정합니다.Gets or sets an array of custom dashes and spaces.

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[]

파선의 반복 대시와 공백의 길이를 지정하는 실수의 배열입니다.An array of real numbers that specifies the lengths of alternating dashes and spaces in dashed lines.

예외

DashPattern 클래스에서 반환된 것과 같은 변경 불가능한 PenPens 속성을 설정한 경우The DashPattern property is set on an immutable Pen, such as those returned by the Pens class.

예제

다음 코드 예제에서는 설정의 결과 DashCap, DashPattern, 및 SmoothingMode 속성.The following code example demonstrates the effects of setting the DashCap, DashPattern, and SmoothingMode properties.

이 예제에서는 Windows Forms를 사용 하 여 사용 하도록 설계 되었습니다.This example is designed to be used with Windows Forms. 양식과 호출 코드를 붙여 합니다 ShowPensAndSmoothingMode 폼을 처리 하는 경우 메서드 Paint 이벤트를 전달 e 으로 PaintEventArgs합니다.Paste the code into a form and call the ShowPensAndSmoothingMode method when handling the form's Paint event, passing e as 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

설명

이외의 값을 할당 null 이 속성에는 설정 합니다 DashStyle 이 대 한 속성 PenCustom.Assigning a value other than null to this property will set the DashStyle property for this Pen to Custom.

요소는 dashArray 대시 패턴에서 각 대시 및 간격의 길이 설정 하는 배열입니다.The elements in the dashArray array set the length of each dash and space in the dash pattern. 대시의 길이 설정 하는 첫 번째 요소, 공간의 길이 설정 하는 두 번째 요소, 세 번째 요소는 dash 및 등의 길이 설정 합니다.The first element sets the length of a dash, the second element sets the length of a space, the third element sets the length of a dash, and so on. 따라서 각 요소에는 0이 아닌 양수 여야 합니다.Consequently, each element should be a non-zero positive number.

각 대시 및 대시 패턴의 길이가 배열의 요소 값의 제품과의 너비는 Pen합니다.The length of each dash and space in the dash pattern is the product of the element value in the array and the width of the Pen.

적용 대상