?
Solved

Minimise parent form when minimising a showmodal child

Posted on 2006-05-31
4
Medium Priority
?
310 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:mikelittlewood
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:saravananvg
ID: 16804911
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
 
LVL 6

Accepted Solution

by:
saravananvg earned 375 total points
ID: 16804940
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
 
LVL 15

Author Comment

by:mikelittlewood
ID: 16805359
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
 
LVL 15

Author Comment

by:mikelittlewood
ID: 16805443
saravananvg's method worked for what I needed.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question