今天在做項目時,看到一軟體做的懸浮框效果不錯,從網上搜羅了一些資料,未見到有十分好的解決辦法,隻能自已動手,利用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 }