一个MDI程序,有一个主窗口、一个子窗口。
打开子窗口以后,再点击右上角的关闭框会并没有关闭窗口,只是最小化了。请教如何解决。

解决方案 »

  1.   

    你把子窗口free就行了!
    有问题请发信息到我的E-mail:[email protected]
      

  2.   

    把子窗口free,不知道hide可不可以。
      

  3.   

    给你一个通用函数:procedure OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent);
    var
      i: integer;
      Child:TForm;
    begin
      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;
            exit;
          end;
      Child:=TForm(FormClass.NewInstance);
      TForm(fm):=Child;
      Child.Create(AOwner);
    end;这样你每次调用即可:如:  OpenForm(TfrmChild1,frmChild1, self);别忘了在close的时候:  Action:=caFree;
      

  4.   

    我看过DEPHI自带的MDI向导,在他的程序中没有用到FREE,并且我想做到直接点击右上角就可以关闭。
      

  5.   

    在onclose加入:
      Action := caFree
      

  6.   

    如上,
    在子窗口的关闭事件中加入
    action:=caFree
    以后提问请先搜索相关贴子。
    本论坛有很多这个问题的答案。
      

  7.   

    谢谢各位啦,我是一个DEPHI的新手,还请以后多帮助。