Pen.Width Propiedad

Definición

Obtiene o establece el ancho de este objeto Pen, en unidades del objeto Graphics usado para dibujar.Gets or sets the width of this Pen, in units of the Graphics object used for drawing.

public:
 property float Width { float get(); void set(float value); };
public float Width { get; set; }
member this.Width : single with get, set
Public Property Width As Single

Valor de propiedad

Single

Ancho de este Pen.The width of this Pen.

Excepciones

El valor de la propiedad Width se establece en un objeto Pen inmutable, como los devueltos por la clase Pens.The Width 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 Width LineJoin propiedades y en un Pen .The following code example demonstrates the effects of setting the Width and LineJoin properties on a Pen.

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 ShowLineJoin método al controlar el evento del formulario Paint , pasando e como PaintEventArgs .Paste the code into a form and call the ShowLineJoin method when handling the form's Paint event, passing e as 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

Puede tener acceso a la unidad de medida del Graphics objeto mediante su PageUnit propiedad.You can access the unit of measure of the Graphics object using its PageUnit property. La unidad de medida es normalmente píxeles.The unit of measure is typically pixels. Un Width valor de 0 producirá el Pen dibujo como si Width fuera 1.A Width of 0 will result in the Pen drawing as if the Width were 1.

Se aplica a