Pen Pen Pen Pen Class

Definition

Defines an object used to draw lines and curves. This class cannot be inherited.

public ref class Pen sealed : MarshalByRefObject, ICloneable, IDisposable
public sealed class Pen : MarshalByRefObject, ICloneable, IDisposable
type Pen = class
    inherit MarshalByRefObject
    interface ICloneable
    interface IDisposable
Public NotInheritable Class Pen
Inherits MarshalByRefObject
Implements ICloneable, IDisposable
Inheritance
Implements

Examples

The following code example demonstrates constructing a Pen with a Brush and the effects of setting the LineJoin property on a Pen.

This example is designed to be used with Windows Forms. 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

Remarks

A Pen draws a line of specified width and style. Use the DashStyle property to draw several varieties of dashed lines. The line drawn by a Pen can be filled in a variety of fill styles, including solid colors and textures. The fill style depends on brush or texture that is used as the fill object.

Constructors

Pen(Brush) Pen(Brush) Pen(Brush) Pen(Brush)

Initializes a new instance of the Pen class with the specified Brush.

Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single) Pen(Brush, Single)

Initializes a new instance of the Pen class with the specified Brush and Width.

Pen(Color) Pen(Color) Pen(Color) Pen(Color)

Initializes a new instance of the Pen class with the specified color.

Pen(Color, Single) Pen(Color, Single) Pen(Color, Single) Pen(Color, Single)

Initializes a new instance of the Pen class with the specified Color and Width properties.

Properties

Alignment Alignment Alignment Alignment

Gets or sets the alignment for this Pen.

Brush Brush Brush Brush

Gets or sets the Brush that determines attributes of this Pen.

Color Color Color Color

Gets or sets the color of this Pen.

CompoundArray CompoundArray CompoundArray CompoundArray

Gets or sets an array of values that specifies a compound pen. A compound pen draws a compound line made up of parallel lines and spaces.

CustomEndCap CustomEndCap CustomEndCap CustomEndCap

Gets or sets a custom cap to use at the end of lines drawn with this Pen.

CustomStartCap CustomStartCap CustomStartCap CustomStartCap

Gets or sets a custom cap to use at the beginning of lines drawn with this Pen.

DashCap DashCap DashCap DashCap

Gets or sets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen.

DashOffset DashOffset DashOffset DashOffset

Gets or sets the distance from the start of a line to the beginning of a dash pattern.

DashPattern DashPattern DashPattern DashPattern

Gets or sets an array of custom dashes and spaces.

DashStyle DashStyle DashStyle DashStyle

Gets or sets the style used for dashed lines drawn with this Pen.

EndCap EndCap EndCap EndCap

Gets or sets the cap style used at the end of lines drawn with this Pen.

LineJoin LineJoin LineJoin LineJoin

Gets or sets the join style for the ends of two consecutive lines drawn with this Pen.

MiterLimit MiterLimit MiterLimit MiterLimit

Gets or sets the limit of the thickness of the join on a mitered corner.

PenType PenType PenType PenType

Gets the style of lines drawn with this Pen.

StartCap StartCap StartCap StartCap

Gets or sets the cap style used at the beginning of lines drawn with this Pen.

Transform Transform Transform Transform

Gets or sets a copy of the geometric transformation for this Pen.

Width Width Width Width

Gets or sets the width of this Pen, in units of the Graphics object used for drawing.

Methods

Clone() Clone() Clone() Clone()

Creates an exact copy of this Pen.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

Releases all resources used by this Pen.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix) MultiplyTransform(Matrix)

Multiplies the transformation matrix for this Pen by the specified Matrix.

MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder) MultiplyTransform(Matrix, MatrixOrder)

Multiplies the transformation matrix for this Pen by the specified Matrix in the specified order.

ResetTransform() ResetTransform() ResetTransform() ResetTransform()

Resets the geometric transformation matrix for this Pen to identity.

RotateTransform(Single) RotateTransform(Single) RotateTransform(Single) RotateTransform(Single)

Rotates the local geometric transformation by the specified angle. This method prepends the rotation to the transformation.

RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder) RotateTransform(Single, MatrixOrder)

Rotates the local geometric transformation by the specified angle in the specified order.

ScaleTransform(Single, Single) ScaleTransform(Single, Single) ScaleTransform(Single, Single) ScaleTransform(Single, Single)

Scales the local geometric transformation by the specified factors. This method prepends the scaling matrix to the transformation.

ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder) ScaleTransform(Single, Single, MatrixOrder)

Scales the local geometric transformation by the specified factors in the specified order.

SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap) SetLineCap(LineCap, LineCap, DashCap)

Sets the values that determine the style of cap used to end lines drawn by this Pen.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single) TranslateTransform(Single, Single)

Translates the local geometric transformation by the specified dimensions. This method prepends the translation to the transformation.

TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder) TranslateTransform(Single, Single, MatrixOrder)

Translates the local geometric transformation by the specified dimensions in the specified order.

Applies to