 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kenny Young Guest
|
Posted: Thu Nov 18, 2004 10:07 am Post subject: How do I change the panel colour at runtime if I only have t |
|
|
I have a form with many TPanels. I would like at runtime change the colour of the panel by entering the caption of the panel, from some device. How can I do a search in the program to achieve this?
Like… caption == ‘cd’ colour =’RED’
Also, how can I retrieve the name of the icon image in a TImage component at runtime so that I can change the icon image?
Any help would be most appreciated.
|
|
| Back to top |
|
 |
Steve Aletto Guest
|
Posted: Thu Nov 18, 2004 1:22 pm Post subject: Re: How do I change the panel colour at runtime if I only ha |
|
|
| Quote: | I have a form with many TPanels. I would like at runtime
change the colour of the panel by entering the caption of the
panel, from some device. How can I do a search in the program
to achieve this?
Like… caption == ‘cd’ colour =’RED’
|
Try one of the following solutions:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for (int i = 0; i < Form1->ControlCount; i++)
{
if (Form1->Controls[i]->ClassNameIs("TPanel"))
{
TPanel *p = dynamic_cast<TPanel
*>(Form1->Controls[i]);
if (p->Caption == "cd") p->Color = clRed;
}
}
}
void __fastcall TForm1::Button5Click(TObject *Sender)
{
for (int i = 0; i < Form1->ControlCount; i++)
{
TPanel *p = dynamic_cast<TPanel *>(Form1->Controls[i]);
if (p->Caption == "cd") p->Color = clRed;
}
}
The first solution should be safer although the second works for
me as well.
| Quote: | Also, how can I retrieve the name of the icon
image in a TImage component at runtime so that
I can change the icon image?
I'd save it in a completely separate AnsiString variable. |
HTH,
Steve.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|