效果如上:最左行号就是
1.DatagridView添加事件(RowPostPaint)
private void dgvBeforeGZ_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
var dgv = (DataGridView)sender;
if (dgv.RowHeadersVisible)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, e.RowBounds.Width, e.RowBounds.Height);
rectangle.Inflate(-3, 0);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, rectangle, e.InheritedRowStyle.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
}
}
2.其实事件条件后代码直接Ctrl+C/V 就OK了,只有效果就自己调整数值了