当鼠标悬停在特定单元格上时,我希望更改DataGridView中单元格的背景颜色。
尝试的代码:
private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
{
}
当鼠标悬停在特定单元格上时,我希望更改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;
}
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
- Patrick from NDepend team