共用方式為


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 方法作為引數:

Rectangle myRectangle = new Rectangle(100, 50, 80, 40);
myGraphics.DrawEllipse(myPen, myRectangle);
Dim myRectangle As 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)

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

橢圓的螢幕擷取畫面,其中包含弧線及其週框。

另請參閱