请问这个重写OnPaint方法怎么使用

shuaizhen 2004-12-28 05:26:05
override protected void OnPaint(PaintEventArgs e)

{

base.OnPaint(e);

try

{

if(this.DataSource!=null)

{

int yDelta;

System.Drawing .Rectangle cell=this.GetCellBounds(0,0);

int y=cell.Top +2;

e.Graphics.DrawString("编号", this.Font, new SolidBrush(Color.Black), 8, y-18); //

if(this.VisibleRowCount >0)//只在有记录集时在表格中显示序号

{

CurrencyManager cm;

cm = (CurrencyManager) this.BindingContext[this.DataSource, this.DataMember];

if(cm.Count >0)

{

int nRow=-1;

y=41; //为第一行默认高度

while(nRow<0)

{

nRow=this.HitTest (8,y).Row ;

y++;

}

int nCount=0;

while(y<this.Height && nCount<this.VisibleRowCount )

{

string text = string.Format("{0}", nRow+nCount+1);

e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), 10, y);

yDelta = this.GetCellBounds( nRow+nCount,0).Height + 1;//****表示一行高度的参数

y += yDelta;

//如果下面有子行显示序号的区分显示

if(this.IsExpanded (nRow+nCount)&& nRow+nCount+1<cm.Count ) {

y+=this.GetCellBounds (nRow+nCount+1,0).Height +3;

}

nCount++;

}

}

}

}

}

catch

{}

}
如题。
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nga96 2004-12-28
  • 打赏
  • 举报
回复
直接覆盖就是啦
shuaizhen 2004-12-28
  • 打赏
  • 举报
回复
那你可以告诉我怎么用吗?
hotyei 2004-12-28
  • 打赏
  • 举报
回复
还不明白你想怎么样
shuaizhen 2004-12-28
  • 打赏
  • 举报
回复
自己顶一下
freehul 2004-12-28
  • 打赏
  • 举报
回复
顶一下

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧