现在的位置: 首页 > 综合 > 正文

C# winfrom中 DataGridView中显示行号

2013年07月25日 ⁄ 综合 ⁄ 共 504字 ⁄ 字号 评论关闭

在DataGridView里加上这个事件RowPostPaint

private void dataGridView1_[color=red]RowPostPaint[/color](object sender, DataGridViewRowPostPaintEventArgs e)
{
 Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
  e.RowBounds.Location.Y,
  dataGridView1.RowHeadersWidth - 4,
  e.RowBounds.Height);

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

}

抱歉!评论已关闭.