C++ Builder RAD Studio XE7 change color of a Panel

2.7k Views Asked by At

After pushing a button I wanted to change the color of a panel to green:

ErrorDetectorPanel->Brush->Color = clLime;

doesn´t work.

ErrorDetectorPanel->Color = clLime;
ErrorDetectorPanel->Refresh();

doesn´t work.

with this addiction:

ErrorDetectorPanel->ParentColor = false;
ErrorDetectorPanel->Refresh();

it still doesn´t work.

tried it this way:

HBRUSH brush = CreateSolidBrush(RGB(0, 255, 0));
SetWindowLong(ErrorDetectorPanel->Handle,WM_ERASEBKGND, 0);
SetWindowLong(ErrorDetectorPanel->Handle,GCLP_HBRBACKGROUND, (LONG)brush);

TForm transparency is false same result after pushing the button.

How can I do it right?

2

There are 2 best solutions below

0
Vytra Vytra On BEST ANSWER

I use

TPanel *tp[]={Panel454,Panel455,Panel456};

    for(int i=sizeof(tp)/sizeof(tp[0]);--i>=0;){
        tp[i]->ParentBackground=false;
        tp[i]->StyleElements = TStyleElements(); // disable all
//      tp[i]->CleanupInstance();
        tp[i]->Color=clSkyBlue;
        }

if the Themed/Styled controls used.

3
Remy Lebeau On

Setting the TPanel.Color property is the correct solution (it will automatically set ParentColor to false), however you have to disable theming/styling on the TPanel (or the entire program as a whole) in order to use custom coloring. Themed/Styled controls get their coloring from the active theme/style.