我在所有 datagridview 行的末尾放置了一张图片,以便在按下时删除行。 我想在特定单元格鼠标悬停时更改该图片的颜色(以便向用户表明它是一个交互式按钮)。
但是,在所有解决方案中,我发现完整的 DGV 鼠标悬停已得到解释。 我需要什么:了解如何在单元格鼠标悬停期间找到悬停在其上的特定单元格。
最佳答案
如果这是 WindowsForms:
//when mouse is over cell
private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Black;
}
}
//when mouse is leaving cell
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White;
}
}
关于c# - 如何识别 DataGridView 中悬停的特定单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31891615/