C++编译器RAD Studio XE7更改面板的颜色

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

本文关键字:颜色 编译器 RAD Studio XE7 C++      更新时间:2023-10-16

按下按钮后,我想将面板的颜色更改为绿色:

ErrorDetectorPanel->Brush->Color = clLime;

不起作用。

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

不起作用。

有这种瘾:

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

它仍然不起作用。

试着这样做:

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

TForm透明度为false按下按钮后得到相同的结果。

我该怎么做才对?

设置TPanel.Color属性是正确的解决方案(它会自动将ParentColor设置为false),但是您必须禁用TPanel(或整个程序)上的主题化/样式化才能使用自定义着色。主题/样式控件从活动主题/样式中获取颜色。

我使用

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;
        }

如果使用了主题化/样式化控件。