protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex < 0 && e.RowIndex >= 0 && e.RowIndex < this.Rows.Count)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.PaintBackground(e.ClipBounds, true);
e.CellBounds.Y += 5; //垂直居中
e.Graphics.DrawString((e.RowIndex + 1).ToString(), this.Font, Brushes.Black, e.CellBounds, sf);
e.Handled = true;
}
}