DataGridView dgv = new DataGridView();

dgv.TopLeftHeaderCell.Value = "序号";

private void grid_RowPostPaint(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
{
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                grid.RowHeadersWidth - 4,
                e.RowBounds.Height);
 
            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dgv.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dgv.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
 }

或者

private void dataGridView1_RowPostPaint(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)

{
    SolidBrush b = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor);
    e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}

相关文章:

  • 2021-09-11
  • 2021-12-09
  • 2021-12-09
  • 2021-07-31
  • 2021-07-27
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-12-05
  • 2022-02-20
  • 2022-01-26
相关资源
相似解决方案