1
我想在鼠标悬停在特定单元格上时更改datagridview中单元格的背景颜色。datagridview单元格鼠标悬停背景变化
尝试代码:
private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
{
}
我想在鼠标悬停在特定单元格上时更改datagridview中单元格的背景颜色。datagridview单元格鼠标悬停背景变化
尝试代码:
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;
}
您需要一提的'列name'而不是' e.ColumnIndex'为特异细胞。 –
也在DGV构造函数中,您需要设置双缓冲绘制,否则更改单元格样式会引发鼠标移过DGV上的闪烁'this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint,true);' –