周星驰的一部百变金刚,把机器人演绎得出神入化。简直让人赞叹不已,机器人也这么人性化。所以说,电脑是人造的,机器语言也是人创的,要什么效果也是人做出来的。
C#中的DataGridView控件变化多种多样的,只要用心去学,相信这十八般武艺在职场、在软件开发上多有一定的好处。
言归正传,实例代码如下:
①直接绘制上去的方式:
private void dgvFont_RowPostPaint(object sender
, DataGridViewRowPostPaintEventArgs e){
using (SolidBrush b = new SolidBrush(
dgvFont.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(
System.Globalization.CultureInfo.CurrentCulture),
dgvFont.DefaultCellStyle.Font
, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
dgvFont是DataGridView的控件对象,使用的是【显示】下的RowPostPaint事件。using主要是用于自动释放资源的,减少内存的使用。
②无需绘制也可以按序号披上去:
private void dgvFont_CellFormatting(object sender
, DataGridViewCellFormattingEventArgs e)
{
DataGridViewRow CurrentRow = dgvFont.Rows[e.RowIndex];
CurrentRow.HeaderCell.Value = Convert.ToString(e.RowIndex + 1);
}
第①种方式也可以绘制一张图片,把e.Graphics.DrawString改成e.Graphics.DrawImage就可以把图片绘制上去。