C# winfrom中 DataGridView中顯示行號

在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);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章