datagridview上的c#graphics.drawline
我有以下代码:datagridview上的c#graphics.drawline,c#,.net,winforms,graphics,datagridview,C#,.net,Winforms,Graphics,Datagridview,我有以下代码: using (Pen gridPen = new Pen(Color.Black, 1)) { if ((e.RowIndex % 4) == 0) { e.Graphics.DrawLine(gridPen, e.CellBounds.X, e.CellBounds.Top-1, e.CellBounds.Right-1, e.CellBounds.Top-1); }
using (Pen gridPen = new Pen(Color.Black, 1))
{
if ((e.RowIndex % 4) == 0)
{
e.Graphics.DrawLine(gridPen, e.CellBounds.X, e.CellBounds.Top-1, e.CellBounds.Right-1, e.CellBounds.Top-1);
}
}
这确实会每隔4行(根据需要)在datagridview上绘制网格线,但当我在datagridview上滚动时,网格线消失,然后有时会再次出现。有人知道为什么吗?谢谢。我没有测试它,请尝试在
Scroll
事件处理程序中调用DataGrid的Invalidate
方法
祝你好运 这可能取决于上下文。画画很难。