Pen.Width Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Property Value
The width of this Pen.
Exceptions
Examples
The following code example demonstrates the effects of setting the Width and LineJoin properties 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
You can access the unit of measure of the Graphics object using its PageUnit property. The unit of measure is typically pixels. A Width of 0 will result in the Pen drawing as if the Width were 1.
Applies to
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: I hele 2024 udfaser vi GitHub-problemer som feedbackmekanisme for indhold og erstatter det med et nyt feedbacksystem. Du kan få flere oplysninger under:Indsend og få vist feedback om