C#中的DrawClosedCurve函数是一个强大的绘图工具,它可以让用户创建由Point结构的数组定义的闭合基数线条。使用该函数,用户可以创建各种形状,如矩形、圆形、三角形等。
在C#中,DrawClosedCurve函数需要三个参数:画布对象、数组Point和一个表示基线条宽度的整数。用户可以使用数组中的Point结构来指定线条的位置。基线条的宽度可以通过第三个参数来设置,以确保线条不会重叠或覆盖彼此。
绘制完闭合基线条后,用户可以使用DrawLine函数绘制其他形状,如矩形、圆形、三角形等。这些函数与DrawClosedCurve函数非常相似,只是需要指定不同的Point结构数组来指定不同的形状。
DrawClosedCurve(Pen, Point[], Single, FillMode) | 使用指定的张力绘制由 Point 结构数组定义的闭合基数样条。 |
DrawClosedCurve(Pen, PointF[], Single, FillMode) | 使用指定的张力绘制由 PointF 结构数组定义的闭合基数样条。 |
DrawClosedCurve(Pen, Point[]) | 绘制由 Point 结构的数组定义的闭合基数样条。 |
DrawClosedCurve(Pen, PointF[]) | 绘制由 PointF 结构的数组定义的闭合基数样条 |
一个例子
C#protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen pen = new Pen(Color.Black, 3);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Point[] p1 = new Point[]
{ new Point(50,10),
new Point(50,40),
new Point(100,80),
new Point(60,100)
};
//画区域
e.Graphics.DrawClosedCurve(pen, p1);
//填充封闭曲线区域颜色
e.Graphics.FillClosedCurve(new SolidBrush(Color.RebeccaPurple), p1);
}
FillMode 枚举
Alternate | 0 | 指定交替填充模式。 |
Winding | 1 | 指定环绕填充模式。 |
C#public void DrawClosedCurve (System.Drawing.Pen pen, System.Drawing.Point[] points
, float tension, System.Drawing.Drawing2D.FillMode fillmode);
tension
大于或等于 0.0F 的值,该值指定曲线的张力。等于0时就是直线Line
fillmode
FillMode 枚举的成员,它确定填充曲线的方式。 需要此参数但被忽略。
一个例子
C#public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<Point> points = new List<Point>();
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;
foreach (var item in points)
{
e.Graphics.DrawEllipse(new Pen(Color.DarkRed), new Rectangle(item, new Size(5, 5)));
}
if (points.Count > 2)
{
//链接封闭线
e.Graphics.DrawClosedCurve(new Pen(Color.BlueViolet), points.ToArray());
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
points.Add(e.Location);
this.Invalidate();
}
}
本文作者:rick
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!