绘制椭圆代码:
主要语法:pen对象,确定曲线颜色宽度和样式.
用Graphics类的DrawEllipse方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace UseDEllipse
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();//创建Graphics对象
Pen myPen = new Pen(Color.DarkOrange, 3);//创建Pen对象
graphics.DrawEllipse(myPen, 55, 20, 100, 50);//绘制椭圆
}
}
}
圆弧代码:DrawArc方法中参数如下:
pen对象确定弧线的颜色,宽度,样式.rect :Rectangle结构,定义椭圆的边界.startAngle从x轴到弧线的起始点沿顺时针方向度量的角.
用Graphic类中的DrawArc方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace UseDArc
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics ghs = this.CreateGraphics();//实例化Graphics类
Pen myPen = new Pen(Color.DarkRed, 3);//实例化Pen类
Rectangle myRectangle = new Rectangle(50, 20, 100, 60);//定义一个Rectangle结构
ghs.DrawArc(myPen, myRectangle, 180, 180);//绘制圆弧
}
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30117771/viewspace-1415440/
,如需转载,请注明出处,否则将追究法律责任。