Delphi 2009 - create a TPanel at runtime and change its color

给你一囗甜甜゛ 提交于 2019-12-17 16:44:19

问题


got a strange problem: I create a TPanele at runtime and change its color - however, the color is still clBtnFace.

Here' the code:

procedure TForm1.Button1Click(Sender: TObject);
var
  pnlTest : TPanel;
begin
    pnlTest := TPanel.Create(Form1);
    pnlTest.Parent := Form1;
    pnlTest.Width := 100;
    pnlTest.Height := 100;
    pnlTest.Color := clRed;
end; 

Any ideas? Thanks!


回答1:


When you want to have colored panels under a themed OS you have to set ParentBackground to False.




回答2:


Try this :-)

procedure TForm1.Button1Click(Sender: TObject);
var
  pnlTest : TPanel;
begin
    pnlTest := TPanel.Create(Form1);
    pnlTest.Parent := Form1;
    pnlTest.Width := 100;
    pnlTest.Height := 100;
    pnlTest.ParentBackground := false;
    pnlTest.Color := clRed;
end;


来源:https://stackoverflow.com/questions/3778161/delphi-2009-create-a-tpanel-at-runtime-and-change-its-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!