我需要在行之间绘制某种括号,以使用户知道行具有某种关系(我不想合并单元格)。到目前为止看起来不错,但是滚动时会变得一团糟。
我无法弄清楚。是否没有办法画出持久的垂直线以使它们保持秩序?
Private Sub dgcontrol_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles dgcontrol.CellPainting
If sender.Columns(e.ColumnIndex).Name = "xrow2" Then
Dim rec1 As Rectangle = dgcontrol.GetCellDisplayRectangle(2, 0, False)
Dim rec2 As Rectangle = dgcontrol.GetCellDisplayRectangle(2, 1, False)
Dim gridBrush As Brush = New SolidBrush(Color.Red)
Dim gridLinePen As Pen = New Pen(gridBrush, 2)
e.Graphics.DrawLine(gridLinePen, New Point(rec1.X + rec1.Width - 2 - rec1.Width / 5, rec1.Y + rec1.Height / 3), New Point(rec1.X + rec1.Width - 2, rec1.Y + rec1.Height / 3))
e.Graphics.DrawLine(gridLinePen, New Point(rec2.X + rec1.Width - 2 - rec1.Width / 5, rec2.Y + rec2.Height - rec2.Height / 3), New Point(rec2.X + rec1.Width - 2, rec2.Y + rec2.Height - rec2.Height / 3))
e.Graphics.DrawLine(gridLinePen, New Point(rec1.X + rec1.Width - 3, rec1.Y + rec1.Height / 3), New Point(rec2.X + rec1.Width - 3, rec2.Y + rec2.Height - rec2.Height / 3))
e.Handled = False
End If End Sub