tags:

views:

500

answers:

2

Hello

I'd like to show an MDI child window that will use the whole client area, ie. the grey part no the right-side of the taskpane, and have the child window show its titlebar and borders:

http://img149.imageshack.us/img149/3204/delphimdichildwindowwit.jpg

Here's the code, which doesn't work as planned:

procedure TForm1.RzGroup1Items0Click(Sender: TObject);
var
  Form2 : TForm2;
begin
  Form2 := TForm2.Create(Application);

  //BAD : doesn't start at 0,0, and triggers horizontal scrollbar
  Form2.Align := alClient;

  //BAD : doesn't show titlebar and borders
  Form2.WindowState := wsMaximized;

  //BAD : window exceeds width -> horizontal scrollbar shown
  Form2.top     := 0;
  Form2.Left    := 0;
  Form2.Width   := Self.ClientWidth;
  Form2.Height  := Self.ClientHeight;
end;

Is there a way to do this, besides computing the coordinates myself (eg. ClientWidth, etc.)?

Thank you.

A: 

The following code will give you the rect of the MDI client area. Please note that fighting MDI is hard.

Form2.BoundsRect := GetMDIClientAreaBoundsRect(Form1);

function GetMDIClientAreaBoundsRect(MDIForm: TForm): TRect;
begin
  if MDIForm.FormStyle = fsMDIForm then begin
    if not Windows.GetClientRect(MDIForm.ClientHandle, Result) then
      RaiseLastOSError;
  end
  else
    raise Exception.Create('MDIForm is not an MDI form');
end;
Lars Truijens
+1  A: 

The quickest way to do that would be the TILE command.

var
  wFrm : TChildMDI;
begin
  wFrm := TChildMDI.create(self);
  wFrm.Show;
  Tile;
end;

TILE is a method of TForm and if you only have 1 MDI child window it will do exactly what you want. With more that 1 it will then arrange all the visible child windows to fit in a similar layout.

Ryan.

Ryan J. Mills
Thanks guys for the help!
OverTheRainbow