使用OnCellPainting,e.PaintBackground绘制DataGridViewCells背景的一部分

时间:2016-07-22 13:16:00

标签: c# winforms datagridview paint datagridcell

我覆盖了OnCellPainting方法,因此我可以在DataGridView中为某些DataGridViewCells绘制自定义边框

protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
    base.OnCellPainting(e);
    PaintCellBorders(e);
}

最初我的边框正在被绘制,然后在调用方法e.PaintBackground(e.ClipBounds, true)时被绘制。

我已经更新了我的代码,因此它首先绘制背景,然后在顶部绘制我的寄宿生。这种方法很好但理想情况下我希望能够在我绘制的边界内绘制背景颜色(使用e.Graphics.DrawLines(....)

为了测试这个概念,我尝试了以下方法:

Rectangle clipBounds = new Rectangle(10,10,10,10);
e.CellStyle.BackColor = Color.Black;
e.PaintBackground(clipBounds, true);
e.Handled = true;

在我的方法结束时,它不仅仅绘制了我的矩形指定的部分,而且我从根本上错过了任何东西?

0 个答案:

没有答案