How to hide a MDI Child form in Delphi?

前端 未结 2 1404
闹比i
闹比i 2020-12-19 17:11

How can I hide a MDIChild window in Delphi?

I\'m using this code in FormClose() event of my MDI children, but it doesn\'t seem to work:

procedure Tfr         


        
相关标签:
2条回答
  • 2020-12-19 17:16

    You cannot hide an MDI child window. This is a Win32 limitation.

    0 讨论(0)
  • 2020-12-19 17:21

    There is a protected procedure in TCustomForm defined as:

    procedure TCustomForm.VisibleChanging;
    begin
      if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then
        raise EInvalidOperation.Create(SMDIChildNotVisible);
    end;
    

    Override it in your MDI child windows as:

    procedure TMDIChildForm.VisibleChanging;
    begin
      // :-P
    end;
    

    Here's a simple example

    After reading Jeroen's comment, I tried another solution which works as well, but with a little flickering:

    procedure TMDIChildForm.VisibleChanging;
    begin
      if Visible then
        FormStyle := fsNormal
      else
        FormStyle := fsMDIChild;
    end;
    

    Maybe this works on all Windows versions.

    PS: I didn't find any problem with the first solution on Windows 2k3SP2 x86 and Windows 7 Ultimate x86

    0 讨论(0)
提交回复
热议问题