本文轉載:http://www.cnblogs.com/bribe/archive/2013/10/08/3357345.html
今天在做項目時,看到一軟件做的懸浮框效果不錯,從網上搜羅了一些資料,未見到有十分好的解決辦法,只能自已動手,利用datagridview 的ToolTipText
來達到此效果。

以下是我簡單實現的代碼,供參考。后續會再仔細測試,如有問題,會一並作更新:
1 private void dgvProduct_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
2 {
3 if (e.ColumnIndex != -1 && e.RowIndex != -1)
4 {
5 if (ds1 != null && dgvProduct.CurrentRow.IsNewRow == false && dgvProduct.CurrentRow.Cells[0].Value.ToString() != "")
6 {
7 if (dgvProduct[dgvProduct.CurrentCell.ColumnIndex, dgvProduct.CurrentCell.RowIndex].Value.ToString() != "")
8 {
9 dgvProduct[e.ColumnIndex, e.RowIndex].ToolTipText = "當前行基本信息:" + "\n";
10 dgvProduct[e.ColumnIndex, e.RowIndex].ToolTipText += " 全球唯一碼:" + dgvProduct[0, dgvProduct.CurrentCell.RowIndex].Value + "\n";
11 dgvProduct[e.ColumnIndex, e.RowIndex].ToolTipText += " 料號:" + dgvProduct[1, dgvProduct.CurrentCell.RowIndex].Value + "\n";
12 dgvProduct[e.ColumnIndex, e.RowIndex].ToolTipText += " 名稱:" + dgvProduct[2, dgvProduct.CurrentCell.RowIndex].Value + "\n";
13
14
15 }
16 }
17
18 }
19 }

