Pen Constructores

Definición

Inicializa una nueva instancia de la clase Pen con el color especificado.

Sobrecargas

Pen(Brush)

Inicializa una nueva instancia de la clase Pen con el objeto Brush especificado.

Pen(Color)

Inicializa una nueva instancia de la clase Pen con el color especificado.

Pen(Brush, Single)

Inicializa una nueva instancia de la clase Pen con los parámetros Brush y Width especificados.

Pen(Color, Single)

Inicializa una nueva instancia de la clase Pen con las propiedades Color y Width especificadas.

Pen(Brush)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

Inicializa una nueva instancia de la clase Pen con el objeto Brush especificado.

public:
 Pen(System::Drawing::Brush ^ brush);
public Pen (System.Drawing.Brush brush);
new System.Drawing.Pen : System.Drawing.Brush -> System.Drawing.Pen
Public Sub New (brush As Brush)

Parámetros

brush
Brush

Brush que define las propiedades de relleno de este Pen.

Excepciones

brush es null.

Ejemplos

En el ejemplo de código siguiente se muestra cómo construir un Pen objeto con Brush y los efectos de establecer la LineJoin propiedad en .Pen

Este ejemplo está diseñado para usarse con Windows Forms. Pegue el código en un formulario y llame al ShowLineJoin método al controlar el evento del Paint formulario, pasando e como PaintEventArgs.

private:
   void ShowLineJoin( PaintEventArgs^ e )
   {
      // Create a new pen.
      Pen^ skyBluePen = gcnew Pen( Brushes::DeepSkyBlue );

      // Set the pen's width.
      skyBluePen->Width = 8.0F;

      // Set the LineJoin property.
      skyBluePen->LineJoin = System::Drawing::Drawing2D::LineJoin::Bevel;

      // Draw a rectangle.
      e->Graphics->DrawRectangle( skyBluePen, Rectangle(40,40,150,200) );

      //Dispose of the pen.
      delete skyBluePen;
   }
private void ShowLineJoin(PaintEventArgs e)
{

    // Create a new pen.
    Pen skyBluePen = new Pen(Brushes.DeepSkyBlue);

    // Set the pen's width.
    skyBluePen.Width = 8.0F;

    // Set the LineJoin property.
    skyBluePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;

    // Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, 
        new Rectangle(40, 40, 150, 200));

    //Dispose of the pen.
    skyBluePen.Dispose();
}
Private Sub ShowLineJoin(ByVal e As PaintEventArgs)

    ' Create a new pen.
    Dim skyBluePen As New Pen(Brushes.DeepSkyBlue)

    ' Set the pen's width.
    skyBluePen.Width = 8.0F

    ' Set the LineJoin property.
    skyBluePen.LineJoin = Drawing2D.LineJoin.Bevel

    ' Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, _
        New Rectangle(40, 40, 150, 200))

    'Dispose of the pen.
    skyBluePen.Dispose()

End Sub

Comentarios

La Brush propiedad determina cómo dibuja las Pen líneas. Las líneas se dibujan como si fueran rectángulos rellenos, con las características del especificado Brush.

La Width propiedad del nuevo Pen se establece en 1 (valor predeterminado).

Se aplica a

Pen(Color)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

Inicializa una nueva instancia de la clase Pen con el color especificado.

public:
 Pen(System::Drawing::Color color);
public Pen (System.Drawing.Color color);
new System.Drawing.Pen : System.Drawing.Color -> System.Drawing.Pen
Public Sub New (color As Color)

Parámetros

color
Color

Estructura Color que indica el color de este Pen.

Comentarios

La Color propiedad se establece en el color especificado por el color parámetro . La Width propiedad se establece en 1 (valor predeterminado).

Se aplica a

Pen(Brush, Single)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

Inicializa una nueva instancia de la clase Pen con los parámetros Brush y Width especificados.

public:
 Pen(System::Drawing::Brush ^ brush, float width);
public Pen (System.Drawing.Brush brush, float width);
new System.Drawing.Pen : System.Drawing.Brush * single -> System.Drawing.Pen
Public Sub New (brush As Brush, width As Single)

Parámetros

brush
Brush

Brush que determina las características de este Pen.

width
Single

Ancho del nuevo Pen.

Excepciones

brush es null.

Ejemplos

En el ejemplo de código siguiente se crea y Pen se muestran los efectos de establecer las StartCap propiedades y EndCap en .Pen

Este ejemplo está diseñado para usarse con Windows Forms. Pegue el código en un formulario y llame al ShowStartAndEndCaps método al controlar el evento del Paint formulario, pasando e como PaintEventArgs.

private:
   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);
    buttonGraphics.Dispose();
    myPen.Dispose();
}
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)
    buttonGraphics.Dispose()
    myPen.Dispose()
End Sub

Comentarios

Brush se establece en el color especificado en el brush parámetro , la Width propiedad se establece en el valor especificado en el width parámetro y las unidades se establecen Worlden .

Tenga en cuenta que el brush parámetro también especifica la Color propiedad de este Pen.

Si este valor es 0, el ancho de las unidades de dispositivo siempre es de 1 píxel, no se ve afectado por las operaciones de transformación de escala que están en vigor para el objeto Graphics para el Pen que se usa .

Se aplica a

Pen(Color, Single)

Source:
Pen.cs
Source:
Pen.cs
Source:
Pen.cs

Inicializa una nueva instancia de la clase Pen con las propiedades Color y Width especificadas.

public:
 Pen(System::Drawing::Color color, float width);
public Pen (System.Drawing.Color color, float width);
new System.Drawing.Pen : System.Drawing.Color * single -> System.Drawing.Pen
Public Sub New (color As Color, width As Single)

Parámetros

color
Color

Estructura Color que indica el color de este Pen.

width
Single

Valor que indica el ancho de este Pen.

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear y Pen los efectos de establecer las DashCappropiedades , DashPatterny SmoothingMode .

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

La Color propiedad se establece en el color especificado por el color parámetro . La Width propiedad se establece en el valor especificado en el width parámetro . Si este valor es 0, el ancho de las unidades de dispositivo siempre es de 1 píxel, no se ve afectado por las operaciones de transformación de escala que están en vigor para el objeto Graphics para el Pen que se usa .

Se aplica a