同样是重载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 );
}
}
}
博客介绍了重载OnPaint方法的技巧,该方法较为巧妙,无需担心标题显示问题,也不用计算坐标。代码中通过判断数据源是否为空,对可见行进行遍历,使用Graphics.DrawString方法在指定位置绘制文本。
1794

被折叠的 条评论
为什么被折叠?



