//创建GDI对象 由于Graphics 类为密封类,不能被实例化但可以通过其它类方法去创建下面以button类为例创建 Graphics
//实例化random
Random random=new Random();
//创建Graphics
Graphics graphics = button1.CreateGraphics();
Pen pen = new Pen(Brushes.Green);
List<Point>list=new List<Point>();
for(int i=0;i<30;i++)
{
list.Add(new Point(random.Next(0,button1.Width),random.Next(0,button1.Height)));
}
string[] fontname = {"宋体","黑体","隶书","仿宋" };
Point p1 = new Point(10, 10);
Point p2 = new Point(button1.Width,button1.Height);
//绘制线条
graphics.DrawLine(pen, p1, p2);
绘制多线条
graphics.DrawLines(pen, list.ToArray());
//绘制文本
graphics.DrawString(button1.Text, new Font(fontname[random.Next(0,3)], 20, FontStyle.Bold), Brushes.Green, p1);
// int[] p = new int[5];