開啟和封閉曲線
下圖顯示兩個曲線:一個開啟和一個封閉。
封閉曲線具有內部,因此可以填滿筆刷。 Windows GDI+ 中的 Graphics 類別提供下列填滿封閉圖形和曲線的方法:FillRectangle、FillEllipse、FillPie、FillPolygon、FillClosedCurve、Graphics::FillPath和 Graphics::FillRegion。 每當您呼叫其中一個方法時,都必須傳遞其中一個特定筆刷類型的位址(SolidBrush、HatchBrush、TextureBrush、LinearGradientBrush或 PathGradientBrush) 作為自變數。
FillPie 方法是 DrawArc 方法的隨附專案。 就像 DrawArc 方法繪製橢圓形外框的一部分一樣,FillPie 方法會填滿橢圓形內部的一部分。 下列範例會繪製弧線,並填滿橢圓形內部的對應部分。
myGraphics.FillPie(&mySolidBrush, 0, 0, 140, 70, 0, 120);
myGraphics.DrawArc(&myPen, 0, 0, 140, 70, 0, 120);
下圖顯示弧形和填滿的餅圖。
顯示填滿橢圓形圖
FillClosedCurve 方法是 drawClosedCurve 方法的隨附專案。 這兩種方法都會將終點連接到起點,以自動關閉曲線。 下列範例繪製通過 (0, 0), (60, 20), 和 (40, 50) 的曲線。 然後,曲線會自動關閉,方法是將 (40, 50) 連接到起點 (0, 0),內部會填滿純色。
Point myPointArray[] =
{Point(10, 10), Point(60, 20),Point(40, 50)};
myGraphics.DrawClosedCurve(&myPen, myPointArray, 3);
myGraphics.FillClosedCurve(&mySolidBrush, myPointArray, 3, FillModeAlternate)
路徑可以包含數個數位(子路徑)。 Graphics::FillPath 方法會填滿每個圖形的內部。 如果未關閉圖表,Graphics::FillPath 方法會填滿圖表關閉時所要括住的區域。 下列範例會繪製並填滿由弧線、基底曲線、字串和餅圖組成的路徑。
myGraphics.FillPath(&mySolidBrush, &myGraphicsPath);
myGraphics.DrawPath(&myPen, &myGraphicsPath);
下圖顯示填滿實心筆刷前後的路徑。 請注意,字串中的文字是由 Graphics::D rawPath 方法所概述,但未填滿。 它是 Graphics::FillPath 方法,用來繪製字串中字元的內部。