共用方式為


如何:填滿開放圖形

您可以將 物件傳遞 GraphicsPathFillPath 方法,以填滿路徑。 方法 FillPath 會根據目前為路徑設定的填滿模式(替代或纏繞)填滿路徑。 如果路徑有任何開啟的數位,路徑就會填滿,就像這些數位已關閉一樣。 GDI+ 會藉由從終點到起點繪製直線來關閉圖形。

範例

下列範例會建立一個路徑,其中包含一個開啟的圖(弧線)和一個封閉式圖(橢圓形)。 方法 FillPath 會根據預設填滿模式填滿路徑,也就是 Alternate

下圖顯示範常式序代碼的輸出。 請注意,路徑已填滿(根據 Alternate ),仿佛開啟的數位是由直線從結束點到其起點關閉。

Diagram that shows the output of the FillPath method

GraphicsPath path = new GraphicsPath();

// Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120);

// Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100);

Pen pen = new Pen(Color.FromArgb(128, 0, 0, 255), 5);
SolidBrush brush = new SolidBrush(Color.Red);

// The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path);
e.Graphics.DrawPath(pen, path);
Dim path As New GraphicsPath()

' Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120)

' Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100)

Dim pen As New Pen(Color.FromArgb(128, 0, 0, 255), 5)
Dim brush As New SolidBrush(Color.Red)

' The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path)
e.Graphics.DrawPath(pen, path)

編譯程式碼

上述範例是為了搭配 Windows Form 使用而設計,且其需要 PaintEventArgse,這是 Paint 事件處理常式的參數。

另請參閱