表格控件RowPostPaint事件:
private void DataGridViewRowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
Rectangle rl = new Rectangle(e.RowBounds.X, e.RowBounds.Y, dataGridView.RowHeadersWidth - 5, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, Convert.ToString(e.RowIndex + 1), dataGridView.Font, rl, Color.Black, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
}