Graphics.FillPath(Brush, GraphicsPath) 方法

定義

填滿 GraphicsPath的內部。

C#
public void FillPath(System.Drawing.Brush brush, System.Drawing.Drawing2D.GraphicsPath path);

參數

brush
Brush

決定填滿特性的 Brush

path
GraphicsPath

GraphicsPath,表示要填滿的路徑。

例外狀況

brush null

-或-

path null

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:

  • 建立純紅色筆刷。

  • 建立圖形路徑物件。

  • 將省略號新增至圖形路徑。

  • 填入畫面上的路徑。

C#
public void FillPathEllipse(PaintEventArgs e)
{
             
    // Create solid brush.
    SolidBrush redBrush = new SolidBrush(Color.Red);
             
    // Create graphics path object and add ellipse.
    GraphicsPath graphPath = new GraphicsPath();
    graphPath.AddEllipse(0, 0, 200, 100);
             
    // Fill graphics path to screen.
    e.Graphics.FillPath(redBrush, graphPath);
}

備註

GraphicsPath 是由一系列線條和曲線線段所組成。 如果未關閉 path 參數所代表的路徑,則會從最後一個點新增至第一個點以關閉路徑的額外區段。

適用於

產品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10