Pen::GetWidth method (gdipluspen.h)
The Pen::GetWidth method gets the width currently set for this Pen object.
Syntax
REAL GetWidth();
Return value
Type: REAL
This method returns a real number that indicates the width of this Pen object.
Remarks
If you pass the address of a pen to one of the draw methods of a Graphics object, the width of the pen's stroke is dependent on the unit of measure specified in the Graphics object. The default unit of measure is UnitPixel, which is an element of the Unit enumeration.
Examples
The following example creates a Pen object with a specified width and draws a line. The code then gets the width of the pen, creates a second pen based on the width of the first pen, and draws a second line.
VOID Example_GetWidth(HDC hdc)
{
Graphics graphics(hdc);
// Create a pen with a width of 15, and
// use that pen to draw a line.
Pen pen(Color(255, 0, 0, 255), 15);
graphics.DrawLine(&pen, 20, 20, 200, 100);
// Get the width of the pen.
REAL width = pen.GetWidth();
// Create another pen that has the same width.
Pen pen2(Color(255, 0, 255, 0), width);
// Draw a second line.
graphics.DrawLine(&pen2, 20, 60, 200, 140);
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdipluspen.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |