Graphics graphics = e.Graphics;
//绘制实线
using (Pen pen = new Pen(Color.Black, ))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; //实线
graphics.DrawLine(pen,,,,);
}
//画出虚线
using (Pen pen = new Pen(Color.Black, ))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; //虚线
graphics.DrawLine(pen, , , , );
}
//画出矩形
using (Pen pen = new Pen(Color.Black, ))
{
Rectangle rectangle = new Rectangle(,,,);
graphics.DrawRectangle(pen,rectangle);
}
//绘制字符串
string str = "Hello 笨男孩!";
graphics.DrawString(str, this.Font, Brushes.Black, , );
//测量字符串的高度和宽度
SizeF szfTitle = graphics.MeasureString(str, this.Font);
graphics.DrawString(str, this.Font, Brushes.Black, , -(int)szfTitle.Height);
graphics.DrawString("该字符串高度:"+szfTitle.Height+" 字符串宽度:"+szfTitle.Width, this.Font, Brushes.Black, , );
//绘制圆
using(Pen pen = new Pen(Color.Black,))
{
//圆
graphics.DrawEllipse(pen,,,,); //在画板上画椭圆,起始坐标为(10,10),外接矩形的宽为100,高为100 此时就是一个圆
//椭圆
graphics.DrawEllipse(pen, , , , ); //在画板上画椭圆,起始坐标为(10,10),外接矩形的宽为100,高为50 此时就是一个椭圆
}