感觉写些这样的代码很有乐趣性,跟朋友一起在嘻嘻哈哈中讨论着各种各样的问题~从封装控件的角度我没有考虑,为了学习GDI+我决定还是这样写下去。
重写DATAGRIDVIEW 重绘方法
1 public class DataGridViewOverride : DataGridView
2 {
3 protected override void OnPaint(PaintEventArgs e)
4 {
5 base.OnPaint(e);
6 SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
7 int headRowWidth = this.RowHeadersWidth+ this.AutoScrollOffset.X;
8 int headColumnHeiht = this.ColumnHeadersHeight + this.AutoScrollOffset.Y;
9 int columnWidth = this.Columns[0].Width + this.AutoScrollOffset.X;
10 int columnHeiht = this.Rows[0].Height + this.AutoScrollOffset.Y;
11
12 Graphics graphics = this.CreateGraphics();
13
14 Rectangle rectangle = new Rectangle(headRowWidth+1, 3, columnWidth, headColumnHeiht/2);
15 Rectangle rectangle2 = new Rectangle(headRowWidth+1, headColumnHeiht/2+3, columnWidth/2-1, headColumnHeiht / 2-1);
16 Rectangle rectangle3 = new Rectangle(headRowWidth + 1 + columnWidth / 2-1, headColumnHeiht / 2 + 3, columnWidth/2+1, headColumnHeiht / 2 - 1);
17 ControlPaint.DrawBorder3D(e.Graphics, rectangle,
18 Border3DStyle.Raised);
19 ControlPaint.DrawBorder3D(e.Graphics, rectangle2,
20 Border3DStyle.Raised);
21 ControlPaint.DrawBorder3D(e.Graphics, rectangle3,
22 Border3DStyle.Raised);
23 Font font = new Font ("楷体",20.1f);
24 PointF pointF = new PointF((float)rectangle.X+10f, (float)rectangle.Y+10f);
25 graphics.DrawString("哈喽", font, Brushes.Black, pointF);
26 }
27 }
不知道怎么能实现拖动用GDI画出的图形,希望高手帮助!