问题
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