热门关键字:  PHP  Cisco  seo  网络广告 虚拟主机 中文域名

DataGrid(WinForm)显示行号最简单的方法

来源:搜站长搜集 作者:未知 时间:2005-10-23 点击:
同样是重载OnPaint 方法,但是方法应该是比较巧妙的!而且不用担心标题是不是有显示,也不用去计算坐标,很方便的说!


protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);

if(this.DataSource!=null)
{
if( this.VisibleRowCount == 0 )return;

Rectangle currRct;

int iRowCount = this.VisibleRowCount;

string sText = "";

int nowY = 0;

for( int i = 0 ; i < iRowCount ; i++ )
{
currRct = (Rectangle)this.GetCellBounds( i, 0 );
nowY = currRct.Y + 2;
sText = string.Format( " {0}", i+1 );
e.Graphics.DrawString( sText, this.Font, new SolidBrush(Color.Black), 10, nowY );
}

}
}

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
赞助商连接