Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
datagridview上的c#graphics.drawline_C#_.net_Winforms_Graphics_Datagridview - Fatal编程技术网

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
方法


祝你好运

这可能取决于上下文。画画很难。