为 DataGridView 控件添加行号

虽然好像不经常用到,不过还是记下来防止以后用到

        /// <summary>
/// 为 DataGridView 控件添加行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void datagridview1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
datagridview1.RowHeadersWidth,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + ).ToString("d2"),
datagridview1.RowHeadersDefaultCellStyle.Font,
rectangle,
datagridview1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right); }
上一篇:Android学习之基础知识十五 — 最佳UI体验(Material Design实战)


下一篇:Android学习之基础知识十二 — 第二讲:网络编程的最佳实践