当鼠标运行到单元格时,出现气泡,并且气泡朝上。
如图:
关键函数是:tooltip中的函数SetToolTip。
代码如下:
1 private void dgv1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
2 {
3 if (e.RowIndex < 0 || e.ColumnIndex < 0)
4 {
5 return;
6 }
7
8 this.toolTip1.Hide(this.dgv1);
9
10 this.CellColumnIndex = e.ColumnIndex;
11 this.CellRowIndex = e.RowIndex;
12 if (this.CellColumnIndex >= 0 && this.CellRowIndex >= 0)
13 {
14 DataGridViewCell dgvc = this.dgv1[this.CellColumnIndex, this.CellRowIndex];
15 Rectangle rec = dgvc.ContentBounds;
16 string tip = "Tip is " + dgvc.Value.ToString();
17 this.toolTip1.SetToolTip(dgv1, tip);
18
19 }
20
21 }
2 {
3 if (e.RowIndex < 0 || e.ColumnIndex < 0)
4 {
5 return;
6 }
7
8 this.toolTip1.Hide(this.dgv1);
9
10 this.CellColumnIndex = e.ColumnIndex;
11 this.CellRowIndex = e.RowIndex;
12 if (this.CellColumnIndex >= 0 && this.CellRowIndex >= 0)
13 {
14 DataGridViewCell dgvc = this.dgv1[this.CellColumnIndex, this.CellRowIndex];
15 Rectangle rec = dgvc.ContentBounds;
16 string tip = "Tip is " + dgvc.Value.ToString();
17 this.toolTip1.SetToolTip(dgv1, tip);
18
19 }
20
21 }