Pen.DashPattern Właściwość

Definicja

Pobiera lub ustawia tablicę niestandardowych kresków i spacji.

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()

Wartość właściwości

Single[]

Tablica liczb rzeczywistych, która określa długość przemiennej kreski i spacji w liniach przerywanych.

Wyjątki

Właściwość DashPattern jest ustawiana Penna niezmiennym obiekcie , takim jak te zwracane przez klasę Pens .

Przykłady

W poniższym przykładzie kodu przedstawiono efekty ustawiania DashCapwłaściwości , DashPatterni SmoothingMode .

Ten przykład jest przeznaczony do użycia z Windows Forms. Wklej kod do formularza i wywołaj ShowPensAndSmoothingMode metodę podczas obsługi zdarzenia formularza Paint , przekazując e jako 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

Uwagi

Przypisanie wartości innej niż null do tej właściwości spowoduje ustawienie DashStyle właściwości dla tej Pen właściwości na Customwartość .

Elementy w dashArray tablicy ustawiają długość każdej kreski i spacji we wzorcu kreski. Pierwszy element ustawia długość kreski, drugi element ustawia długość spacji, trzeci element ustawia długość kreski itd. W związku z tym każdy element powinien być liczbą niezerową dodatnią.

Długość każdej kreski i spacji we wzorcu kreski jest produktem wartości elementu w tablicy i szerokości elementu Pen.

Dotyczy