用 CreateGraphics 方法创建 Graphics 对象
Graphics g = this.CreateGraphics();
画线,下例是一个棋盘:
//x+=15每一个格子的宽15,y+=15每一个格子的高15 for (int x = 10, y = 10, count = 0; count < 15; x += 15, y += 15, count++) { //220=15*14+10(格子宽*14+期盼最左的线起始x坐标) g.DrawLine(new Pen(Color.Blue), new Point(10, y), new Point(220, y)); g.DrawLine(new Pen(Color.Blue), new Point(x, 10), new Point(x, 220)); }
画椭圆:
g.FillEllipse(Brushes.Black,rtg);