#region 行绘制事件 ,为DataGridView每行写上序号
/// <summary>
/// 行绘制事件 ,为DataGridView每行写上序号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.dataGridView.RowHeadersWidth - 4, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
this.dataGridView.RowHeadersDefaultCellStyle.Font,
rectangle, this.dataGridView.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
#endregion
C# DataGrid 控件在winform里显示行号
最新推荐文章于 2024-01-30 09:33:40 发布