相关疑难解决方法(0)

如何仅绘制DataGridView的单元格背景而不是其内容?

我只需要绘制DataGridView单元格的背景而不是它的Content.But,而我正在绘画时它也会绘制其内容.请帮助我.

我的代码是这样的.

private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex == 0 )

            {
                using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor))
                {
                    using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor))
                    {
                        using (Pen gridLinePen = new Pen(gridBrush))
                        {
                            // Clear cell 
                            e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
                            //Bottom line drawing
                            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1);


                            e.Handled = true;
                        }
                    }
                }
            }
Run Code Online (Sandbox Code Playgroud)

c# datagridview

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

datagridview ×1