GDI+ 中的椭圆和弧线

可以使用 DrawEllipse 类的 DrawArcGraphics 方法轻松绘制椭圆和弧线。

绘制椭圆

若要绘制椭圆,需要一个 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)

绘制弧线

弧是椭圆的一部分。 若要绘制弧线,请调用 DrawArc 类的 Graphics 方法。 DrawArc 方法的参数与 DrawEllipse 方法的参数相同,但 DrawArc 需要起始角度和扫描角度。 以下示例绘制一段弧线,其起始角度为 30 度,扫描角度为 180 度:

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

下图显示了弧线、椭圆形和边框。

带弧线和范围框的椭圆形的屏幕截图。

另请参阅