共用方式為


GDI+ 中的橢圓形和弧形

您可以使用 Graphics 類別的 DrawEllipseDrawArc 方法輕鬆地繪製橢圓形和弧形。

繪製橢圓形

若要繪製橢圓形,您需要 Graphics 物件和 Pen 物件。 Graphics 物件提供 DrawEllipse 方法,而 Pen 物件則是儲存用來產生橢圓形的線條屬性,例如寬度和色彩。 Pen 物件會當成其中一個引數傳遞給 DrawEllipse 方法。 其他傳遞給 DrawEllipse 方法的引數會指定橢圓形的週框。 下圖顯示橢圓形及其週框。

橢圓形和弧形

下列範例會繪製一個橢圓形;其週框寬度為 80、高度為 40,而左上角為 (100, 50):

        myGraphics.DrawEllipse(myPen, 100, 50, 80, 40)

myGraphics.DrawEllipse(myPen, 100, 50, 80, 40);

DrawEllipseGraphics 類別的多載方法,因此可使用許多種方法提供引數給它。 例如,您可以建構 Rectangle 並將 Rectangle 當做引數傳遞給 DrawEllipse 方法:

        Dim myRectangle As New Rectangle(100, 50, 80, 40)
        myGraphics.DrawEllipse(myPen, myRectangle)

Rectangle myRectangle = new Rectangle(100, 50, 80, 40);
myGraphics.DrawEllipse(myPen, myRectangle);

繪製弧形

弧形是橢圓形的一部分。 若要繪製弧形,您可呼叫 Graphics 類別的 DrawArc 方法。 DrawArc 方法的參數和 DrawEllipse 方法的參數相同,但 DrawArc 必須有起始的角度和泛用角度。 下列範例繪製起始角度為 30 度、泛用角度為 180 度的弧形:

        myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180)

myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);

下圖顯示弧形、橢圓形和週框。

橢圓形和弧形

請參閱

工作

HOW TO:建立繪製的圖形物件

HOW TO:建立畫筆

HOW TO:繪製外框形狀

參考

System.Drawing.Graphics

System.Drawing.Pen

其他資源

線條、曲線和形狀