111,125
社区成员
发帖
与我相关
我的任务
分享
private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Color color = DataGridView1.RowHeadersDefaultCellStyle.ForeColor;
if (DataGridView1.Rows[e.RowIndex].Selected)
color = DataGridView1.RowHeadersDefaultCellStyle.SelectionForeColor;
else
color = DataGridView1.RowHeadersDefaultCellStyle.ForeColor;
using (SolidBrush b = new SolidBrush(color))
{
e.Graphics.DrawString((e.RowIndex+1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X+20, e.RowBounds.Location.Y+6);
}
}