C# 鼠標懸停在datagridview的某單元格,顯示懸浮框效果


 

本文轉載: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         }
復制代碼
復制代碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM