具有双缓冲区的{C#DataGridView黑色选择

时间:2018-02-28 11:08:42

标签: c# datagridview

我试图通过DataGridView中的边框实现透明选择。问题是,DoubleBuffer设置为True,我的行选择就像图片中的黑色一样。把它转到false解决问题,但让我的网格闪烁。

Black row

这是我用来为所选行创建红色边框的代码:

    private void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
    {
        if (dgv.Rows[e.RowIndex].Selected)
        {
            using (Pen pen = new Pen(Color.Red))
            {
                int penWidth = 2;

                pen.Width = penWidth;

                int x = e.RowBounds.Left + (penWidth / 2);
                int y = e.RowBounds.Top + (penWidth / 2);
                int width = e.RowBounds.Width - penWidth;
                int height = e.RowBounds.Height - penWidth;

                e.Graphics.DrawRectangle(pen, x, y, width, height);
            }
        }
    }

我还在dgv' s SelectionBackColor

中将Transparent设为SelectionForeColor,将Black设为RowDefaultCellsStyle

在保持DataGridViewDoubleBuffer的同时,是否可以在True中进行透明选择?

0 个答案:

没有答案