展开全部
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
if(e.RowIndex<10)
e.Graphics.DrawString(Convert.ToString("00"+e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 100&&e.RowIndex>10)
e.Graphics.DrawString(Convert.ToString("0" + e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 1000 && e.RowIndex > 100)
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
}
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString("序号", temp.Font, b, 8, 5);
}
}
你看着改动下吧,基本就是这样的
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
if(e.RowIndex<10)
e.Graphics.DrawString(Convert.ToString("00"+e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 100&&e.RowIndex>10)
e.Graphics.DrawString(Convert.ToString("0" + e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 1000 && e.RowIndex > 100)
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
}
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString("序号", temp.Font, b, 8, 5);
}
}
你看着改动下吧,基本就是这样的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询