using System.Drawing;
画园
private void button1_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics();//将本窗体创建为画板 //Graphics不可以用New来实例化。 Pen pen = new Pen(Color.Red,20);//创建一只笔,定义颜色和宽度 g.DrawEllipse(pen ,100,100,200,200);//画园 g.FillEllipse(Brushes.Blue,100,100,200,200);//填充颜色 }
画方
private void button2_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen pen = new Pen(Color.Red,20); g.DrawRectangle(pen,20,20,600,20); g.FillRectangle(Brushes.Blue,20,20,600,20); }
画线
private void button3_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen pen = new Pen(Color.Red, 20); g.DrawLine(pen,60,90,500,90); }
清空
private void button4_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(Form1.DefaultBackColor) ;//清空画板,更改为窗体默认的背景颜色 }
多边形,圆弧,扇形
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pen = new Pen(Color.Black,3); Point[] p = {new Point(10,100),new Point(200,100),new Point(200,200),new Point(10,200) }; //弧线 g.DrawArc(pen,0,50,200,200,0,360);//坐标X,坐标Y,宽度,高度,起始角度,旋转角度 //扇形 g.DrawPie(pen,0,200,300,200,0,120); g.DrawPolygon(pen,p); g.Dispose(); }