添加 RowPostPaint 事件,事件代码如下:

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               this.dataGridView1.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                this.dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);

        }

相关文章:

  • 2022-01-16
  • 2022-03-03
  • 2022-12-23
  • 2022-01-13
  • 2021-08-21
猜你喜欢
  • 2021-08-21
  • 2022-12-23
  • 2021-05-30
  • 2021-08-16
相关资源
相似解决方案