Datagridview单元格鼠标悬停背景色改变

本文关键字:背景色 改变 悬停 鼠标 单元格 Datagridview | 更新日期: 2023-09-27 18:02:15

当鼠标悬停在特定单元格上时,我想改变datagridview中单元格的背景色。

尝试代码:

private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
        {
        }

Datagridview单元格鼠标悬停背景色改变

CellMouseMove事件上试试

private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Blue;
}

您需要CellMouseLeave事件来恢复颜色

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.White;
}