panel 窗口停靠功能的实现
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, ExtCtrls;
type
TForm1 = class(TForm)
tlb1: TToolBar;
btn1: TToolButton;
pnl1: TPanel;
btn2: TToolButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure pnl1DockDrop(Sender: TObject; Source: TDragDockObject; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
try
form2:=TForm2.Create(Application);
form2.ManualDock(pnl1,nil,alClient);
Form2.Show;
except
MessageBox(0, '窗体创建错误', '产生严重例外错误', MB_OK +
MB_ICONSTOP);
end;
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
try
form3 := TForm3.Create(Self);
form3.ManualDock(pnl1,nil,alClient);
form3.show;
except
MessageBox(0, '窗体创建错误', '产生严重例外错误', MB_OK +
MB_ICONSTOP);
end;
end;
procedure TForm1.pnl1DockDrop(Sender: TObject; Source: TDragDockObject; X,
Y: Integer);
var
i: integer;
begin
i := 0;
while (i <= Pnl1.ControlCount - 1) and (pnl1.ControlCount > 1) do
begin
if Pnl1.Controls[i] is TForm then
begin
pnl1.Controls[i].Free;
end
else
i := i + 1;
end;
end;
end.
另外设置form2、form3的 Onclose属性: Action := CaFree;
Form2 := Nil;
OnCloseQuery属性: CanClose := True;