1 out of 5 rated this helpful - Rate this topic

Pen Class

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

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)
public sealed class Pen : MarshalByRefObject, ICloneable, 
	IDisposable

The Pen type exposes the following members.

  NameDescription
Public methodPen(Brush)Initializes a new instance of the Pen class with the specified Brush.
Public methodPen(Color)Initializes a new instance of the Pen class with the specified color.
Public methodPen(Brush, Single)Initializes a new instance of the Pen class with the specified Brush and Width.
Public methodPen(Color, Single)Initializes a new instance of the Pen class with the specified Color and Width properties.
Top
  NameDescription
Public propertyAlignmentGets or sets the alignment for this Pen.
Public propertyBrushGets or sets the Brush that determines attributes of this Pen.
Public propertyColorGets or sets the color of this Pen.
Public propertyCompoundArrayGets 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.
Public propertyCustomEndCapGets or sets a custom cap to use at the end of lines drawn with this Pen.
Public propertyCustomStartCapGets or sets a custom cap to use at the beginning of lines drawn with this Pen.
Public propertyDashCapGets or sets the cap style used at the end of the dashes that make up dashed lines drawn with this Pen.
Public propertyDashOffsetGets or sets the distance from the start of a line to the beginning of a dash pattern.
Public propertyDashPatternGets or sets an array of custom dashes and spaces.
Public propertyDashStyleGets or sets the style used for dashed lines drawn with this Pen.
Public propertyEndCapGets or sets the cap style used at the end of lines drawn with this Pen.
Public propertyLineJoinGets or sets the join style for the ends of two consecutive lines drawn with this Pen.
Public propertyMiterLimitGets or sets the limit of the thickness of the join on a mitered corner.
Public propertyPenTypeGets the style of lines drawn with this Pen.
Public propertyStartCapGets or sets the cap style used at the beginning of lines drawn with this Pen.
Public propertyTransformGets or sets a copy of the geometric transformation for this Pen.
Public propertyWidthGets or sets the width of this Pen, in units of the Graphics object used for drawing.
Top
  NameDescription
Public methodCloneCreates an exact copy of this Pen.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDisposeReleases all resources used by this Pen.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodMultiplyTransform(Matrix)Multiplies the transformation matrix for this Pen by the specified Matrix.
Public methodMultiplyTransform(Matrix, MatrixOrder)Multiplies the transformation matrix for this Pen by the specified Matrix in the specified order.
Public methodResetTransformResets the geometric transformation matrix for this Pen to identity.
Public methodRotateTransform(Single)Rotates the local geometric transformation by the specified angle. This method prepends the rotation to the transformation.
Public methodRotateTransform(Single, MatrixOrder)Rotates the local geometric transformation by the specified angle in the specified order.
Public methodScaleTransform(Single, Single)Scales the local geometric transformation by the specified factors. This method prepends the scaling matrix to the transformation.
Public methodScaleTransform(Single, Single, MatrixOrder)Scales the local geometric transformation by the specified factors in the specified order.
Public methodSetLineCapSets the values that determine the style of cap used to end lines drawn by this Pen.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTranslateTransform(Single, Single)Translates the local geometric transformation by the specified dimensions. This method prepends the translation to the transformation.
Public methodTranslateTransform(Single, Single, MatrixOrder)Translates the local geometric transformation by the specified dimensions in the specified order.
Top

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.

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

}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.