Delphi 中 动态创建的Panel无法改变颜色的解决办法

刚开始代码如下:

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;
上一篇:实验吧之【简单的sql注入 1、2、3】


下一篇:解析js中作用域、闭包——从一道经典的面试题开始