【Winform】DataGridView在RowHead内显示行号
Private Sub Grid_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles Grid.RowPostPaint
Dim dgv As DataGridView
dgv = TryCast(sender, DataGridView)
Dim rt As New Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth - 2, e.RowBounds.Height)
TextRenderer.DrawText(e.Graphics, Format(e.RowIndex + 1, "00"), dgv.RowHeadersDefaultCellStyle.Font, rt, Color.Black)
End Sub
Dim dgv As DataGridView
dgv = TryCast(sender, DataGridView)
Dim rt As New Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth - 2, e.RowBounds.Height)
TextRenderer.DrawText(e.Graphics, Format(e.RowIndex + 1, "00"), dgv.RowHeadersDefaultCellStyle.Font, rt, Color.Black)
End Sub
![]() | 本作品采用 知识共享署名-非商业性使用 2.5 中国大陆许可协议进行许可。 |