|
以下是DataGridView添加行号的代码: private void dgv1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { try { Rectangle rectangle = new Rectangle(e.RowBounds.Location.X , Convert.ToInt32( e.RowBounds.Location.Y + (e.RowBounds.Height - dgv1.RowHeadersDefaultCellStyle.Font.Size) / 2), dgv1.RowHeadersWidth - 4, e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgv1.RowHeadersDefaultCellStyle.Font, rectangle, dgv1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.Right);
} catch (Exception ex) { Console.Write("dgv1_RowPostPaint:" + ex.Message); } } |