编写按钮的单击事件如下: if mdichildcount>0 then 判断子窗体个数,只显示一个 begin activemdichild.Close; end; Application.CreateForm(TForm3, Form3);//创建要显示的窗体 form3.show;//显示窗体
Try if Application.MainForm.MDIChildCount>0 then ActiveMDIChild.Close; Finally TFormSale.Create(Self);//这是子窗体 End;
Try if Application.MainForm.MDIChildCount>0 then ActiveMDIChild.Close; Finally TFormSale.Create(Self);//这是子窗体,MDIChild窗体自己创建自己显示,不用Show End;
打开前首先查找一遍i=0; while i < FrmMain.MDIChildCount do if FrmMain.MDIChildren[i].ClassName = 'xxxx' then break; inc(i); end; if i = FrmMain.MDIChildCount then begin // 没找到一样的,填写创建代码 end else begin // 还原大小,显示在最顶端 .... // FrmMain.MDIChildren[i].Show; end;
设置一个全局变量,在第一次CreateMDIChild的时候设置为1,子窗体free的时候设置为0;
然后在CreateMDIChild的时候先判断这个变量是0还是1就可以了
if mdichildcount>0 then 判断子窗体个数,只显示一个
begin
activemdichild.Close;
end;
Application.CreateForm(TForm3, Form3);//创建要显示的窗体
form3.show;//显示窗体
if Application.MainForm.MDIChildCount>0 then
ActiveMDIChild.Close;
Finally
TFormSale.Create(Self);//这是子窗体
End;
if Application.MainForm.MDIChildCount>0 then
ActiveMDIChild.Close;
Finally
TFormSale.Create(Self);//这是子窗体,MDIChild窗体自己创建自己显示,不用Show
End;
while i < FrmMain.MDIChildCount do
if FrmMain.MDIChildren[i].ClassName = 'xxxx' then
break;
inc(i);
end;
if i = FrmMain.MDIChildCount then begin
// 没找到一样的,填写创建代码
end
else begin
// 还原大小,显示在最顶端
....
//
FrmMain.MDIChildren[i].Show;
end;