如何隐藏子窗体

解决方案 »

  1.   

    子窗体名称.hide
    或者 子窗体名称.visual:=false;
      

  2.   

    你试过没有
    MDI子窗体是不允许使用这种方法的
      

  3.   

    子窗体名称.hide
    或者 子窗体名称.visual:=false;
      

  4.   

    ShowWindow(Form1.MDIChildren[要隐藏的子窗体].Handle, SW_Hide);
      

  5.   

    要显示:
     SetWindowPos(Form1.MDIChildren[要隐藏的子窗体].Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_SHOWWINDOW);
      

  6.   

    The ShowWindow function sets the specified window's show state. BOOL ShowWindow(    HWND hWnd, // handle of window
        int nCmdShow  // show state of window
       );
     ParametershWndIdentifies the window. nCmdShowSpecifies how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls, this parameter can be one of the following values: Value Meaning
    SW_HIDE Hides the window and activates another window.
    SW_MAXIMIZE Maximizes the specified window.
    SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
    SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    SW_SHOW Activates the window and displays it in its current size and position. 
    SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. 
    SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
    SW_SHOWNA Displays the window in its current state. The active window remains active.
    SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
    SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
     Return ValuesIf the window was previously visible, the return value is nonzero. 
    If the window was previously hidden, the return value is zero. ResThe first time a program calls ShowWindow, it uses the WinMain function's nCmdShow parameter as its nCmdShow parameter. Subsequent calls to ShowWindow must use one of the values in the given list, instead of the one specified by the WinMain function's nCmdShow parameter. 
    As noted in the discussion of the nCmdShow parameter, the nCmdShow value is ignored in the first call to ShowWindow if the program that launched the application specifies startup information in the STARTUPINFO structure. In this case, ShowWindow uses the information specified in the STARTUPINFO structure to show the window. On subsequent calls, the application must call ShowWindow with nCmdShow set to SW_SHOWDEFAULT to use the startup information provided by the program that launched the application. For example, Program Manager specifies that applications start with a minimized main window. This behavior is designed for the following situations: ?Applications create their main window by calling CreateWindow with the WS_VISIBLE flag set. 
    ?Applications create their main window by calling CreateWindow with the WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag set to make it visible.  See AlsoCreateProcess, CreateWindow, ShowOwnedPopups, STARTUPINFO, WinMain
      

  7.   

    在子窗体的close事件里Action:=caFree;
    子窗体:=NIL;
      

  8.   

    欢迎大家加入DELPHI程序员群1805366 ,一起交流技术!
      

  9.   

    在子窗体的close事件里Action:=caFree;
    Show时动态创建
      

  10.   

    窗体已经创建好了才能SHOW的吧MDI窗体包含很很多子窗体
    在你关闭一个子窗体的时候,他要消失或释放,这个看你怎么处理
    但是当用户再点击按纽要显示这个窗体时候
    如果子窗体被释放要重新创建并显示
    如果子窗体未被释放要显示在最前面现在我要做一个子窗体类
    让其他的子窗体都从我这个类继承出去
    而不是TFORM
      

  11.   

    问题已经解决
    谢谢各位关注特将代码上传,供大家观看unit fChildForm;interface
    uses Forms,fMenuAboutForm,Menus,fIAddDeleteMenu,fIIUD,Dialogs,messages,fINextPrev;type
    TChildForm = class(TForm,IIUD)
    private
      state:integer;
      lastLeft:integer;
      lastTop:integer;
      lastWidth:integer;
      lastHeight:integer;
    public
      friendMenuItem : TMenuItem;
      parent : IAddDeleteMenu;
      constructor create(var theParent :IAddDeleteMenu);
      destructor destroy();  procedure notify(Sender: TObject);virtual;
      procedure closeOperation(Sender: TObject; var Action: TCloseAction);virtual;
      procedure addVO(); virtual;
      procedure updateVO(); virtual;
      procedure deleteVO(); virtual;  procedure moveNext(); virtual;
      procedure movePrev(); virtual;  procedure WndProc(var message:Tmessage);override;end;
    implementationprocedure TChildForm.WndProc(var message:TMessage);
    begin   if (message.Msg = WM_SYSCOMMAND) and ((message.WParam = 61488) or (message.WParam = 61490)) then
           begin
              if state = 0 then //原壮
                 begin
                    //存储原尺寸
                    lastLeft := self.Left;
                    lastTop := self.Top;
                    lastWidth := self.Width;
                    lastHeight := self.Height;
                    //设置最大尺寸
                    self.Width := parent.getWorkWidth ;
                    self.Height := parent.getWorkHeight ;
                    self.Left := 0;
                    self.Top := 0;
                    state := 1;//状态为最大化
                 end
              else
                 begin
                    self.Left := lastLeft;
                    self.Top := lastTop;
                    self.Width := lastWidth;
                    self.Height := lastHeight;
                    state := 0;//状态为原态
                 end;
           end
       else
          inherited WndProc(message);
    end;
      

  12.   

    在closeing事件中写
    action:=free
    子窗体:=nil
      

  13.   

    发错了,不好意思
    这个问题我用单例模式已经解决了
    unit fSubject;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ADODB, ExtCtrls,  dxtrprds, Grids, DBGridEh ,
      Menus, dxmdaset, StdCtrls,fChildForm,fIAddDeleteMenu,fSubjectVO, RzPanel,
      fDataModule, DBActns, ActnList;type
      TSubjectSetForm = class(TChildForm)
        ctlDBGridEh: TDBGridEh;
        DataSource: TDataSource;
        Label1: TLabel;
        RzPanel1: TRzPanel;
        ADOQuery: TADOQuery;
        procedure FormCreate(Sender: TObject);
        class function getInstance(var theParent :IAddDeleteMenu):TSubjectSetForm;
      private
      constructor create(var theParent :IAddDeleteMenu);
        { Private declarations }
      public
         procedure closeOperation(Sender: TObject; var Action: TCloseAction);override;
         destructor destroy();     procedure addVO(); override;
         procedure updateVO(); override;
         procedure deleteVO(); override;     procedure moveNext(); override;
         procedure movePrev(); override;
        { Public declarations }
      end;
      
    var subjectSetForm : TSubjectSetForm;
    implementation
    uses fAddUpdateSubjectForm,fSubjectDAO;{$R *.dfm}procedure TSubjectSetForm.moveNext();
    begin
       if self.ADOQuery.RecordCount >0 then
       begin
          ADOQuery.Next ;
          if ADOQuery.Eof then
             ADOQuery.First;
       end;
    end;procedure TSubjectSetForm.movePrev();
    begin
       if self.ADOQuery.RecordCount >0 then
       begin
          ADOQuery.Prior  ;
          if ADOQuery.Bof then
             ADOQuery.Last ;   end;
    end;class function TSubjectSetForm.getInstance(var theParent :IAddDeleteMenu):TSubjectSetForm;
    begin
       if subjectSetForm = nil then
             subjectSetForm := create(theParent);
       Result := subjectSetForm;end;procedure TSubjectSetForm.closeOperation(Sender: TObject; var Action: TCloseAction);
    begin
       subjectSetForm := nil;
       inherited;
    end;constructor TSubjectSetForm.create(var theParent : IAddDeleteMenu);
    begin
       inherited create(theParent);
       subjectSetForm := self;
       ADOQuery.Connection := ZDataModule.sqlConnection;
       ADOQuery.SQL.Text  := 'select subject_id ,memo  from subject';
       ADOQuery.Active := true;
    end;destructor TSubjectSetForm.destroy();
    begin
        inherited;
    end;
    procedure TSubjectSetForm.addVO();
    var  subjectSetForm:TAddUpdateSubject;
    begin
         subjectSetForm := TAddUpdateSubject.create();
         subjectSetForm.ShowModal;
         ADOQuery.Close;
         ADOQuery.Open;
    end;procedure TSubjectSetForm.updateVO();
    var subjectVO:TSubjectVO;
    var subjectEditForm:TAddUpdateSubject;
    begin   if self.ADOQuery.RecordCount  >0 then
       begin
           subjectVO := TSubjectVO.Create();
           subjectVO.setSubjectID(ctlDBGridEh.Fields[0].AsInteger  );
           subjectVO.setMemo(ctlDBGridEh.Fields[1].AsString);
           subjectEditForm := TAddUpdateSubject.create(subjectVO);
           subjectEditForm.ShowModal;
           ADOQuery.Close;
           ADOQuery.Open;
           subjectVO.Free;
       end;end;procedure TSubjectSetForm.deleteVO();
    var subject_id :Integer;
    begin
       if self.ADOQuery.RecordCount  >0 then
       begin
           if application.MessageBox('确定删除指定的科目吗?','删除确认',MB_OKCANCEL) = IDCANCEL THEN
              exit; 
           subject_id := ctlDBGridEh.Fields[0].AsInteger;
           ZDataModule.SubjectDAO.deleteSubjectVO(subject_id);
           ADOQuery.Close;
           ADOQuery.Open;
       end;
    end;procedure TSubjectSetForm.FormCreate(Sender: TObject);
    begin
        ADOQuery.Active := true;
    end;end.