简体   繁体   English

C ++ Builder RAD Studio XE7更改面板的颜色

[英]C++ Builder RAD Studio XE7 change color of a Panel

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. 按下按钮后,TForm透明度为假,结果相同。

How can I do it right? 我该怎么办?

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. 设置TPanel.Color属性是正确的解决方案(它将自动将ParentColor设置为false),但是必须使用TPanel (或整个程序)禁用主题设置/样式,才能使用自定义着色。 Themed/Styled controls get their coloring from the active theme/style. 主题/样式控件从活动的主题/样式中获得颜色。

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. 如果使用了主题/样式控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM