Pen.DashPattern Propiedad

Definición

Obtiene o establece una matriz de guiones y espacios personalizados.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()

Valor de propiedad

Single[]

Una matriz de números reales que especifica las longitudes de los guiones y espacios alternos que forman las líneas discontinuas.An array of real numbers that specifies the lengths of alternating dashes and spaces in dashed lines.

Excepciones

El valor de la propiedad DashPattern se establece en un objeto Pen inmutable, como los devueltos por la clase Pens.The DashPattern property is set on an immutable Pen, such as those returned by the Pens class.

Ejemplos

En el ejemplo de código siguiente se muestran los efectos de establecer las DashCap DashPattern propiedades, y SmoothingMode .The following code example demonstrates the effects of setting the DashCap, DashPattern, and SmoothingMode properties.

Este ejemplo está diseñado para usarse con Windows Forms.This example is designed to be used with Windows Forms. Pegue el código en un formulario y llame al ShowPensAndSmoothingMode método al controlar el evento del formulario Paint , pasando e como 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

Comentarios

Si se asigna un valor distinto de null a esta propiedad, se establecerá la DashStyle propiedad de este Pen en Custom .Assigning a value other than null to this property will set the DashStyle property for this Pen to Custom.

Los elementos de la dashArray matriz establecen la longitud de cada guión y espacio del patrón de guiones.The elements in the dashArray array set the length of each dash and space in the dash pattern. El primer elemento establece la longitud de un guión, el segundo elemento establece la longitud de un espacio, el tercer elemento establece la longitud de un guión, etc.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. Por consiguiente, cada elemento debe ser un número positivo distinto de cero.Consequently, each element should be a non-zero positive number.

La longitud de cada guión y espacio del modelo de guiones es el producto del valor del elemento en la matriz y el ancho de 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.

Se aplica a