BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I change the panel colour at runtime if I only have t

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Kenny Young
Guest





PostPosted: Thu Nov 18, 2004 10:07 am    Post subject: How do I change the panel colour at runtime if I only have t Reply with 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’

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





PostPosted: Thu Nov 18, 2004 1:22 pm    Post subject: Re: How do I change the panel colour at runtime if I only ha Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.