如何清除ScrollBox中的所有动态添加的TImage和TLabel

netying 2009-04-08 07:58:14
首先:

for(int i=0;i<5;i++)
{
TImage *img=new TImage(ScrollBox2);
img->Parent=ScrollBox2;
img->Width=220;
img->Height=175;

img->Left=10+(img->Width+50)*(i%3);
img->Top=10+(img->Height+40)*(i/3);

img->AutoSize=false;
img->Stretch=true;
img->Center=true;

img->Picture->LoadFromFile("d:\\mmm.bmp");
}

如上我在ScrollBox2上添加了5个image

然后我想删除所有的image,即让scrollbox恢复空白状态:我用如下代码

TComponent *Temp;
for (int I = ScrollBox2->ComponentCount - 1; I >= 0; I--)

{
Temp = ScrollBox2->Components[I];
ScrollBox2->RemoveComponent(Temp);
}


可是图象依然存在,不知道该如何操作?

...全文
148 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
netying 2009-04-08
  • 打赏
  • 举报
回复
多谢多谢
CACACACACA 2009-04-08
  • 打赏
  • 举报
回复
removecomponents只是表示 Image和ScrollBox脱离了"拥有和被拥有"的关系. Image并没有死掉.
并且Image的Parent应该还是ScrollBox

CACACACACA 2009-04-08
  • 打赏
  • 举报
回复
ScrollBox1->DestroyComponents;
ScrollBox1->Invalidate;
netying 2009-04-08
  • 打赏
  • 举报
回复
多谢ccrun
那为什么removecomponents无效呢
痞子酷 2009-04-08
  • 打赏
  • 举报
回复
楼上正解!
ccrun.com 2009-04-08
  • 打赏
  • 举报
回复
删除的时候:
TComponent *Temp;
for (int I = ScrollBox1->ComponentCount - 1; I >= 0; I--)
{
Temp = ScrollBox1->Components[I];
delete Temp;
}

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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