Pen Constructor (Brush^, Single)
.NET Framework (current version)
Namespace:
System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Return to top
Assembly: System.Drawing (in System.Drawing.dll)
| Exception | Condition |
|---|---|
| ArgumentNullException | 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 = 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; }
.NET Framework
Available since 1.1
Available since 1.1
Show: