首页 > 代码库 > C#画图

C#画图

画线

private void Form1_Load(object sender, EventArgs e)
{
this.Paint += new PaintEventHandler(Form1_Paint);
}

//画线
void Form1_Paint(object sender, PaintEventArgs e)
{

Pen blackPen = new Pen(Color.Black, 2);//创建画笔
Point point1;//起点坐标
Point point2;//终点坐标

int x=10;

int y=10;

int w=100;

int h=100;
point1 = new Point(x, y);
point2 = new Point(x, h);
e.Graphics.DrawLine(blackPen, point1, point2);//竖线
point1 = new Point(x, y);
point2 = new Point(w, y);
e.Graphics.DrawLine(blackPen, point1, point2);//横线

Brush brush = new SolidBrush(Color.Black);//字体颜色

   Font captionFontT = new Font("宋体", 14);//字体样式

e.Graphics.DrawString("显示内容", captionFontT, brush, x+10, y, StringFormat.GenericDefault);//画内容

}

C#画图