请大家帮我看看StringGrid是什么问题,Cell刷新得很厉害!CPU占用率上到了100%

iahcn 2004-12-24 09:28:44
这个问题应该如何解决?

程序的地址!
http://www.tmpack.com/Grid.exe

请大家帮我看看!
谢谢了!
...全文
169 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
庄鱼 2004-12-24
  • 打赏
  • 举报
回复
在做特殊显示时用的,比方说你希望第二列是绿色,就可以这样:
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(ACol!=1)return;
TStringGrid *grid = static_cast<StringGrid*>(Sender);
TCanvas *ca = grid->Canvas;
ca->Font->Color = clGreen;
ca->TextOutA(Rect.Left+2,Rect.Top+2,grid->Cell[ACol][ARow]);
}
iahcn 2004-12-24
  • 打赏
  • 举报
回复
谢谢 FreeFice(庄鱼) 结帖散分 你能不能回答一下我最后一个问题!
呵呵 我是以前做SQL的 在BCB方面还是一个新手!请多多指教!
iahcn 2004-12-24
  • 打赏
  • 举报
回复
问题已经解决 ,为什么用StringGrid1DrawCell就刷新得这么厉害
这个方法该时候时候用比较合适?
庄鱼 2004-12-24
  • 打赏
  • 举报
回复
你如果怕别人改动列宽,可以将goColSizing设为false就行了,这样在DrawDell里就不需要设定宽度了,因为Cell的宽度变化会导致Cell的重画!
iahcn 2004-12-24
  • 打赏
  • 举报
回复
谢谢 我来试试看 !
庄鱼 2004-12-24
  • 打赏
  • 举报
回复
问题在这里:
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
StringGrid1->ColWidths[0]=20;
StringGrid1->ColWidths[1]=100;
StringGrid1->ColWidths[2]=100;
StringGrid1->ColWidths[3]=100;
StringGrid1->ColWidths[4]=125;
StringGrid1->Cells[0][0]="ID";
StringGrid1->Cells[1][0]="姓名";
StringGrid1->Cells[2][0]="性别";
StringGrid1->Cells[3][0]="户籍";
StringGrid1->Cells[4][0]="出生时间";
}
你可以这样:
void __fastcall TForm1::Init()
{
StringGrid1->ColWidths[0]=20;
StringGrid1->ColWidths[1]=100;
StringGrid1->ColWidths[2]=100;
StringGrid1->ColWidths[3]=100;
StringGrid1->ColWidths[4]=125;
StringGrid1->Cells[0][0]="ID";
StringGrid1->Cells[1][0]="姓名";
StringGrid1->Cells[2][0]="性别";
StringGrid1->Cells[3][0]="户籍";
StringGrid1->Cells[4][0]="出生时间";
}
然后在Show或Create函数里加上Init();就行了
iahcn 2004-12-24
  • 打赏
  • 举报
回复
OK 谢谢!

源码地址:
http://www.tmpack.com/GridSpp.rar
庄鱼 2004-12-24
  • 打赏
  • 举报
回复
有关DrawCell部分,或者刷新部分,如果仅是测试程序的话,也可都放上来
iahcn 2004-12-24
  • 打赏
  • 举报
回复
那我把源吗发上去?
庄鱼 2004-12-24
  • 打赏
  • 举报
回复
没有源码没法判断

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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