panel出现在不同的窗体上。
调用代码:
CreatePnlMess(ProcureForm,380,1,'无需重复!');
FORM1调用,如果PANEL还没有消失的话,Form2在调用PANEL会出现,但是2秒后会报错。
可能是计时器销毁的时候报错了!
创建时的代码
if Frm.FindComponent(Frm.Name + '_PnlMess') <> nil then begin
exit;
end else begin
pnl := TPanel.Create(Frm);
with pnl do begin
Name := Frm.Name + '_PnlMess';
Parent := Frm;
Height := 70;
Width := Wid;
ParentBackground := False;
Color := $00F0CAA6;
Left := (Frm.Width - pnl.Width) div 2;
Top := (Frm.Height - pnl.Height) div 2;
BringToFront;
Caption := '';
end;
lbl := TLabel.Create(pnl);
with lbl do begin
//Name := Frm.Name + 'LblMess';
Parent := pnl;
Caption := Text;
Left := (pnl.Width - lbl.Canvas.TextWidth(lbl.Caption)) div 2;
Top := (pnl.Height - Height) div 2;
AutoSize := True;
BringToFront;
Font.Size := 10;
Font.Style := [fsBold];
end;
Ico := TIcon.Create;
MainForm.ilMess.GetIcon(iL, Ico);
img := TImage.Create(pnl);
with img do begin
//Name := Frm.Name + 'ImgMess';
Parent := pnl;
Height := 32;
Width := 32;
Left := 25;
Top := (pnl.Height - Height) div 2;
BringToFront;
Picture.Assign(Ico);
end;
Trm := TTimer.Create(Frm);
with Trm do begin
//Name := Frm.Name + 'TrmMess';
Interval := 2000;
OnTimer := MainForm.CurrentTimer;
Enabled := True;
end;
end;
倒计时销毁的代码
img.Free;
Ico.Free;
lbl.Free;
Trm.Free;
pnl.Free;