private GridUnit[] grids = new GridUnit[11]; //保存风格中各个格的中点位置,边框矩形 /// <summary> /// 绘制风格线 /// </summary> /// <param name="e"></param> private void DrawGridLine() { Graphics gr = CreateGraphics(); gr.Clear(Color.White); int uHeight = this.Height / 3; //网格单元高度 int uWidth = this.Width / 3; //网格单元宽度 float pointY = uHeight / 2; //第一个网格单元中数字的起始Y坐标 float pointX = uWidth / 2; //第一个网格单元中数字的起始X坐标 //水平线 gr.DrawLine(new Pen(Color.Red, 2), new Point(0, 0), new Point(this.Width, 0)); gr.DrawLine(new Pen(Color.Red, 2), new Point(0, uHeight * 1), new Point(this.Width, uHeight * 1)); gr.DrawLine(new Pen(Color.Red, 2), new Point(0, uHeight * 2), new Point(this.Width, uHeight * 2)); gr.DrawLine(new Pen(Color.Red, 2), new Point(0, uHeight * 3), new Point(this.Width, uHeight * 3)); //垂直线 gr.DrawLine(new Pen(Color.Red, 2), new Point(0, 0), new Point(0, this.Height)); gr.DrawLine(new Pen(Color.Red, 2), new Point(uWidth * 1, 0), new Point(uWidth * 1, this.Height)); gr.DrawLine(new Pen(Color.Red, 2), new Point(uWidth * 2, 0), new Point(uWidth * 2, this.Height)); gr.DrawLine(new Pen(Color.Red, 2), new Point(uWidth * 3, 0), new Point(uWidth * 3, this.Height)); int fontSize = uWidth / 5; //绘文本 for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int x = (int)(pointX + uWidth * i); int y = (int)(pointY + uHeight * j); grids[j * 3 + i + 1] = new GridUnit(new Point(x, y), new Rectangle(uWidth * i, uHeight * j, uWidth, uHeight)); gr.DrawString((j * 3 + i + 1).ToString(), new Font(FontFamily.Families.First(), fontSize > 0 ? fontSize : 1), new SolidBrush(Color.Red), new PointF(pointX + uWidth * i, pointY + uHeight * j)); } } }