Pen::GetWidth 方法 (gdipluspen.h)

Pen::GetWidth方法會取得此Pen物件的目前設定寬度。

Syntax

REAL GetWidth();

傳回值

類型: REAL

這個方法會傳回實際數位,指出這個 Pen 物件的寬度。

備註

如果您將手寫筆的位址傳遞至 Graphics 物件的其中一個繪製方法,筆刷筆觸的寬度取決於 Graphics 物件中指定的量值單位。 測量的預設單位是 UnitPixel,這是 Unit 列舉的元素。

範例

下列範例會建立具有指定寬度的 Pen 物件,並繪製線條。 然後程式碼會取得畫筆的寬度、根據第一個畫筆的寬度建立第二個畫筆,然後繪製第二行。

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

需求

   
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 gdipluspen.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

Pen::SetWidth

畫筆、線條和矩形

設定畫筆寬度和對齊方式