【问题标题】:datagridview cell mouse hover backcolor changedatagridview 单元格鼠标悬停背景颜色更改
【发布时间】:2015-09-29 00:19:54
【问题描述】:

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

尝试过的代码:

private void dataGridView_whateventwillcomehere(object sender, DataGridViewCellEventArgs e)
        {

        }

【问题讨论】:

    标签: c# .net c#-4.0 datagridview mouseover


    【解决方案1】:

    CellMouseMove Event 上试试这个

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

    【讨论】:

    • 您需要提及column name 而不是e.ColumnIndex 用于purticular cell。
    • 同样在 DGV 构造函数中,您需要设置双缓冲绘画,否则更改单元格样式会导致鼠标在 DGV 上移动时闪烁this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
    猜你喜欢
    • 2014-03-27
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2016-05-27
    • 2013-10-07
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多