您的位置:首页 > 其它

为DataGridView控件描行序号

2009-02-01 22:00 218 查看
该功能主要用到了DataGridView的 RowPostPaint事件,为动态描绘,经测试,效率基本满意。该事件直接调用静态方法DrawingRowIndex(DataGridView dgv, DataGridViewRowPostPaintEventArgs e),传入datagridview实例和参数e.

public static void DrawingRowIndex(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)

{
//描绘文本的位置

Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,

dgv.RowHeadersWidth - 13,//行头宽
e.RowBounds.Height);//宽

//描绘行头文本

TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),//内容
dgv.RowHeadersDefaultCellStyle.Font,//字体

rectangle,//位置
dgv.RowHeadersDefaultCellStyle.ForeColor,//颜色

TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}

转帖自

http://blog.csdn.net/A1027/archive/2008/08/05/2768885.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐