0

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?

Lama Dingo
  • 123
  • 1
  • 11

2 Answers2

3

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thanks for the fast answer. I didn´t use any theming/styling, so what else could cause the problem? – Lama Dingo Nov 25 '15 at 09:48
  • Application theming is enabled by default. – Remy Lebeau Nov 26 '15 at 05:12
  • Tried this site: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/disablethemes_xml.html still doesn´t work. You got some steps how to fix it? – Lama Dingo Nov 26 '15 at 09:18
1

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.