datagridview单元格鼠标悬停背景色更改 [英] datagridview cell mouse hover backcolor change

查看:113
本文介绍了datagridview单元格鼠标悬停背景色更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在鼠标悬停在特定单元格上时更改datagridview中单元格的背景色.

i want to change the backcolor of cell in datagridview while mouse hover on particular cell.

尝试的代码:

private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
        {

        }

推荐答案

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;
}

这篇关于datagridview单元格鼠标悬停背景色更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆