Delphi中动态创建的Panel无法改变颜色的解决办法(要把Panel的ParentBackground设为False)

刚开始代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
Panel: TPanel;
begin
Panel := TPanel.Create(Form1);
Panel.Name := 'pnlPreVideo';
Panel.Parent := Form1;
Panel.OnClick := Panel1Click;
MoveWindow(Panel.Handle, , , , , True);
end; procedure TForm1.Panel1Click(Sender: TObject);
begin
if (Sender as TPanel).Name ='pnlPreVideo' then
(Sender as TPanel).Color := clGreen;
end;

单击时,颜色不变,问网友,原来是一个BUG,更正后代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
Panel: TPanel;
begin
Panel := TPanel.Create(Form1);
Panel.Name := 'pnlPreVideo';
Panel.ParentBackground := False;
Panel.Parent := Form1;
Panel.OnClick := Panel1Click;
MoveWindow(Panel.Handle, , , , , True);
end; procedure TForm1.Panel1Click(Sender: TObject);
begin
if (Sender as TPanel).Name ='pnlPreVideo' then
(Sender as TPanel).Color := clGreen;
end;

http://www.cnblogs.com/jxgxy/p/3248408.html

上一篇:Flink - InputGate


下一篇:JAVA基础--方法的重写overwrite 和 重载overload