Minimise parent form when minimising a showmodal child

I guess the title says it all, but how do you minimise the main parent form when minimising a child form that is showmodal.
Also I guess maximising the child form again.
LVL 15
mikelittlewoodAsked:
Who is Participating?
 
saravananvgConnect With a Mentor Commented:
Hello Sir,

  You could use the following code as well for MDI parent and child forms

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
     procedure WMSysCommand
     (var Msg: TWMSysCommand) ;
    message WM_SYSCOMMAND;

  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.WMSysCommand;
begin
   if (Msg.CmdType = SC_MINIMIZE) then
    Form1.WindowState := wsMinimized
   else if (Msg.CmdType = SC_MAXIMIZE) then
    Form1.WindowState := wsMaximized;

   DefaultHandler(Msg) ;
end;

Where Form1 is the MDI form and Form2 is the MDI child form. We are capturing when the form2 is being minimized or maximized and performing the operation accordingly.

with regards,
padmaja.
0
 
saravananvgCommented:
Hello Sir,

 First of all you cannot show a child form as modal as it gives an error saying "Cannot Hide an MDI child form'. Because we cannot make a visible window Modal. Hence both contradict. If you wish to perform the same operation using normal forms then give the following instructions.


 procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Action = caMinimize then
    Form1.WindowState := wsMinimized;
end;

with regards,
padmaja.
0
 
mikelittlewoodAuthor Commented:
I dont think I explained myself correctly, this is not an MDI application, just 2 forms

ie

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    Form2 := TForm2.Create;
    Form2.ShowModal
  finally
    FreeAndNil(Form2)
  end;
end;
0
 
mikelittlewoodAuthor Commented:
saravananvg's method worked for what I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.