Graphics.DrawArc方法用于绘制表示由一对坐标,宽度和高度指定的椭圆的一部分的圆弧。此方法的重载列表中有4种方法,如下所示:
- DrawArc(Pen,Rectangle,Single,Single)方法
- DrawArc(Pen,RectangleF,Single,Single)方法
- DrawArc(Pen,Int32,Int32,Int32,Int32,Int32,Int32)方法
- DrawArc(Pen,Single,Single,Single,Single,Single,Single)方法
DrawArc(笔,矩形,单,单)
此方法用于绘制表示由Rectangle结构指定的椭圆的一部分的弧。
Syntax: public void DrawArc (System.Drawing.Pen pen, System.Drawing.Rectangle rect, float startAngle, float sweepAngle)
Parameters:
pen: Determines the color, width, and style of the arc.
rect: Determines the smallest rectangle in which the ellipse just perfectly fits into.
startAngle: Angle in degrees measured clockwise from the x-axis to the starting point of the arc.
sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
异常:如果笔为null,则此方法将提供ArgumentNullException。
例子:
// C# program to illustrate the
// DrawArc(Pen, Rectangle, Single,
// Single) Method
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace GFG {
class PrintableForm : Form {
// Main Method
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Reactangle with specifies x1,
// y1, x2, y2 respectively
Rectangle rect = new Rectangle(0, 0, 100, 200);
// Create start and sweep angles on ellipse.
float startAngle = 45.0F;
float sweepAngle = 270.0F;
// Draw arc to screen.
e.Graphics.DrawArc(blackPen, rect,
startAngle, sweepAngle);
}
}
}
输出:
DrawArc(Pen,RectangleF,Single,Single)
此方法用于绘制表示由RectangleF结构指定的椭圆的一部分的弧。
Syntax: public void DrawArc (System.Drawing.Pen pen, System.Drawing.RectangleF rect, float startAngle, float sweepAngle);
Parameters:
pen: Determines the color, width, and style of the arc.
rect: Determines the smallest rectangle in which the ellipse just perfectly fits into.
startAngle: Angle in degrees measured clockwise from the x-axis to the starting point of the arc.sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
异常:如果笔为null,则此方法将提供ArgumentNullException。
范例1:
// C# program to illustrate the
// DrawArc(Pen, RectangleF,
// Single, Single) Method
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace GFG {
class PrintableForm : Form {
// Main Method
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
// Create pen
Pen blackPen = new Pen(Color.Black, 3);
// Reactangle with specifies x1,
// y1, x2, y2 respectively
RectangleF rect = new RectangleF(0.0F,
0.0F, 100.0F, 200.0F);
// Create start and sweep
// angles on an ellipse.
float startAngle = 45.0F;
float sweepAngle = 270.0F;
// Draw arc to screen.
e.Graphics.DrawArc(blackPen, rect,
startAngle, sweepAngle);
}
}
}
输出:
DrawArc(笔,单,单,单,单,单,单)
此方法用于绘制表示由一对坐标,宽度和高度指定的椭圆的一部分的圆弧。
Syntax: public void DrawArc (System.Drawing.Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
Parameters:
pen: Pen determines the color, width, and style of the line.
x: The abscissa of the upper-left corner of the rectangle that defines the ellipse.
y: The ordinate of the upper-left corner of the rectangle that defines the ellipse.
width: Width of the rectangle that defines the ellipse or more specifically we can say the diameter of the ellipse in abscissa.
height: Height of the rectangle that defines the ellipse or more specifically we can say the diameter of the ellipse in ordinate.
startAngle: Angle in degrees measured clockwise from the x-axis to the starting point of the arc.
sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to the ending point of the arc.
异常:如果笔为null,则此方法将提供ArgumentNullException。
范例1:
// C# program to draw a circle
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace GFG {
class PrintableForm : Form {
// Main Method
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create coordinates of the rectangle
// to the bound ellipse.
int x = 0;
int y = 0;
int width = 100;
int height = 200;
// Create start and sweep
// angles on ellipse.
int startAngle = 0;
int sweepAngle = 360;
// Draw arc to screen.
e.Graphics.DrawArc(blackPen, x, y, width,
height, startAngle, sweepAngle);
}
}
}
输出:
范例2:
// C# program to draw GFG
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace GFG {
class PrintableForm : Form {
// Main Method
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Creates letter G
e.Graphics.DrawArc(blackPen, 10,
10, 100, 200, 0, 315);
e.Graphics.DrawLine(blackPen,
60, 110, 110, 110);
// Creates letter F
e.Graphics.DrawLine(blackPen,
130, 10, 130, 210);
e.Graphics.DrawLine(blackPen,
130, 10, 200, 10);
e.Graphics.DrawLine(blackPen,
130, 110, 170, 110);
// Creates the next letter G
e.Graphics.DrawArc(blackPen,
210, 10, 100, 200, 0, 315);
e.Graphics.DrawLine(blackPen,
260, 110, 310, 110);
}
}
}
输出:
DrawArc(Pen,Int32,Int32,Int32,Int32,Int32,Int32)
此方法用于绘制表示由一对坐标,宽度和高度指定的椭圆的一部分的圆弧。
Syntax: public void DrawArc (System.Drawing.Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle);
Parameters:
pen: Pen determines the color, width, and style of the line.
x: The abscissa of the upper-left corner of the rectangle that defines the ellipse.
y: The ordinate of the upper-left corner of the rectangle that defines the ellipse.
width: Width of the rectangle that defines the ellipse or more specifically we can say the diameter of the ellipse in abscissa.
height: Height of the rectangle that defines the ellipse or more specifically we can say the diameter of the ellipse inordinate.
startAngle: Angle in degrees measured clockwise from the x-axis to the starting point of the arc.
sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.
异常:如果笔为null,则此方法将提供ArgumentNullException。
例子:
// C# program to draw a circle
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace GFG {
class PrintableForm : Form {
// Main Method
public static void Main()
{
Application.Run(new PrintableForm());
}
public PrintableForm()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create coordinates of the rectangle
// to the bound ellipse.
float x = 0.0F;
float y = 0.0F;
float width = 100.0F;
float height = 200.0F;
// Create start and sweep
// angles on the ellipse.
float startAngle = 0.0F;
float sweepAngle = 360.0F;
// Draw arc to screen.
e.Graphics.DrawArc(blackPen, x, y, width,
height, startAngle, sweepAngle);
}
}
}
输出:
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.graphics.drawarc?view=netframework-4.7.2