Private Sub dgvData_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgvData.RowPostPaint
Dim rectangle As Rectangle
Try
' Add Row Number
rectangle = New Rectangle(e.RowBounds.Location.X, Convert.ToInt32(e.RowBounds.Location.Y + (e.RowBounds.Height - dgvData.RowHeadersDefaultCellStyle.Font.Size) / 2), dgvData.RowHeadersWidth - 4, e.RowBounds.Height)
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvData.RowHeadersDefaultCellStyle.Font, rectangle, dgvData.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.Right)
Catch ex As Exception
Throw ex
End Try
End Sub
转载于:https://www.cnblogs.com/fengzhifengyi/archive/2009/04/06/1430361.html