为 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 + 1).ToString("d2"), datagridview1.RowHeadersDefaultCellStyle.Font, rectangle, datagridview1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right); }
想找一个无人的角落发呆……