c# - 如何识别 DataGridView 中悬停的特定单元格

标签 c# winforms datagridview cell

我在所有 datagridview 行的末尾放置了一张图片,以便在按下时删除行。 enter image description here 我想在特定单元格鼠标悬停时更改该图片的颜色(以便向用户表明它是一个交互式按钮)。

但是,在所有解决方案中,我发现完整的 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/

相关文章:

c# - Windows 窗体应用程序数据库

C# - 如何在删除行后刷新 DataGridView

c# - 在 DataGridView 中使用自定义控件

c# - 确定 DataGridView 中的单元格位置

c# - 将范围行从一个数据表添加到另一个

c# - 更改 DataGridView CellMouseClick 上的单元格背景色

c# - 接收 json 作为字符串始终为 null

c# - 如何解决 Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable' ERROR

C# 日期时间小时分钟验证

c# - 在 FlowLayoutPanel 滚动期间,背景扭曲 + 闪烁