新建一个窗体,在options中设置它为非自动创建,然后用下面的代码
var
Found:Boolean;
I:Integer;
begin
Found:= False;
I:= 0;
while (not found) and (I< MDIChildCount ) do
if MDIChildren[I] = Form2 then Found:= True
else I:=I+1;
if not found then
begin
form2:= Tform2.Create(self as TComponent);
end
ELSE
form2.Show;
procedure TFrm_Main.OpenMDIForm(FormClass: TFormClass; var fm;
AOwner: TComPonent);
var
i: integer; //打开mdi子窗体
Child:TForm;
begin
if mdichildcount>10 then
begin
Application.MessageBox('打开窗体过多,造成系统资源紧张,请关闭部分窗体。','福思特系列软件',
MB_DEFBUTTON1+ MB_ICONINFORMATION+MB_OK);
end;
for i := 0 to Screen.FormCount -1 do
if Screen.Forms[i].ClassType=FormClass then
begin
Child:=Screen.Forms[i];
if Child.WindowState=wsMinimized then
ShowWindow(Child.handle,SW_SHOWNORMAL)
else
ShowWindow(Child.handle,SW_SHOWNA);
if (not Child.Visible) then Child.Visible:=True;
Child.BringToFront;
Child.Setfocus;
TForm(fm):=Child;
child.left:=(screen.width - child.width )div 2;
child.top:=screen.height div 2 - child.height*5 div 8 ;//*5 div 8;
exit;
end;
Child:=TForm(FormClass.NewInstance);
TForm(fm):=Child;
Child.Create(AOwner);
child.left:=(screen.width - child.width )div 2;
child.top:=screen.height div 2 - child.height*5 div 8;//*5 div 8;
end;