DataGridView显示行号

Private Sub DataGridView1_RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Dim Rectangle As Rectangle = New Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, DataGridView1.RowHeadersWidth - 4, e.RowBounds.Height)
        TextRenderer.DrawText(e.Graphics,
                              (e.RowIndex + 1).ToString(),
                              DataGridView1.RowHeadersDefaultCellStyle.Font,
                              Rectangle,
                              DataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                              TextFormatFlags.HorizontalCenter + TextFormatFlags.VerticalCenter)
    End Sub

猜你喜欢

转载自www.cnblogs.com/rf8862/p/12274905.html
今日推荐