Pen::SetDashStyle 方法 (gdipluspen.h)

Pen::SetDashStyle 方法會設定此 Pen 物件的虛線樣式。

語法

Status SetDashStyle(
  [in] DashStyle dashStyle
);

參數

[in] dashStyle

類型: DashStyle

DashStyle 列舉的 元素,指定這個 Pen 對象的虛線樣式。

傳回值

類型: 狀態

如果方法成功,它會傳回 Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其中一個其他元素。

備註

虛線中的虛線長度取決於虛線樣式和 Pen 物件的寬度。 在虛線中分隔兩個虛線的空間長度等於 Pen 物件的寬度。

範例

下列範例會建立 Pen 對象、設定虛線樣式,並繪製線條。 然後程式代碼會重設虛線樣式、繪製第二行、再次重設虛線樣式,然後繪製第三行。

VOID Example_SetDashStyle(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Pen object.
   Pen pen(Color(255, 0, 0, 255), 15);

   // Set the dash style for the pen, and draw a dashed line.
   pen.SetDashStyle(DashStyleDash);
   graphics.DrawLine(&pen, 0, 50, 400, 150);

   // Reset the dash style for the pen, and draw a second line.
   pen.SetDashStyle(DashStyleDot);
   graphics.DrawLine(&pen, 0, 80, 400, 180); 

   // Reset the dash style for the pen, and draw a third line.
   pen.SetDashStyle(DashStyleDashDot);
   graphics.DrawLine(&pen, 0, 110, 400, 210); 
}

規格需求

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

另請參閱

繪製自定義虛線

Pen::GetDashCap

Pen::GetDashOffset

Pen::GetDashPattern

Pen::GetDashPatternCount

Pen::GetDashStyle

Pen::SetDashCap

Pen::SetDashOffset

Pen::SetDashPattern

畫筆、線條和矩形