Share via


橢圓形和弧形

橢圓形的範圍是由其週框 (Bounding Rectangle) 指定。下圖顯示橢圓形及其週框。

如果要繪製橢圓形,您必須使用 Graphics 物件和 Pen 物件。Graphics 物件提供 DrawEllipse 方法,而 Pen 物件則會儲存用來產生橢圓形的線條的屬性,例如寬度和色彩。Pen 物件會被當作引數傳遞給 DrawEllipse 方法。其他傳遞給 DrawEllipse 方法的引數會指定橢圓形的週框。下列範例會繪製一個橢圓形;其週框寬度為 80、高度為 40,而左上角為 (100, 50):

myGraphics.DrawEllipse(myPen, 100, 50, 80, 40)
[C#]
myGraphics.DrawEllipse(myPen, 100, 50, 80, 40);

DrawEllipseGraphics 類別的多載方法,因此可使用許多種方法將它當作引數使用。例如,您可以建立 Rectangle 物件,然後將 Rectangle 物件當作引數傳遞給 DrawEllipse 方法:

Dim myRectangle As New Rectangle(100, 50, 80, 40)
myGraphics.DrawEllipse(myPen, myRectangle)
[C#]
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)
[C#]
myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);

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