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) ;//清空画板,更改为窗体默认的背景颜色 }
原文:https://www.cnblogs.com/Luck1996/p/11973355.html