Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Pen Constructor (Brush, Single)

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

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public Pen(
	Brush brush,
	float width


Type: System.Drawing.Brush

A Brush that determines the characteristics of this Pen.

Type: System.Single

The width of the new Pen.


brush is null.

The Brush is set to the color specified in the brush parameter, the Width property is set to the value specified in the width parameter, and the units are set to World.

Note that the brush parameter also specifies the Color property of this Pen.

A width of 0 will result in the Pen drawing as if the width were 1.

The following code example creates a Pen and demonstrates the effects of setting the StartCap and EndCap properties on a Pen.

This example is designed to be used with Windows Forms. Paste the code into a form and call the ShowStartAndEndCaps method when handling the form's Paint event, passing e as PaintEventArgs.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft