Delphi动态创建子窗口例子
procedure TForm1.mlskntlbr2ItemDown(Sender: TObject; const ItemIndex: Integer);
begin
case ItemIndex of
0:
ShowSubForm(Form2, TForm2);
1:
ShowSubForm(Form3, TForm3);
2:
; // 分隔线
3:
ShowSubForm(Form4, TForm4);
4:
;
5:
;
6:
;
7:
;
end;
end;
procedure TForm1.ShowSubForm(var Ref; AFormClass: TFormClass);
var
Instance: TForm;
begin
if not Assigned(TForm(Ref)) then
begin
Instance := TForm(AFormClass.NewInstance);
TForm(Ref) := Instance;
Instance.Create(Self);
Instance.Parent := pnl2;
Instance.Align := alClient;
Instance.BorderStyle := bsNone;
end
else
Instance := TForm(Ref);
Instance.Show;
end;