Title: Sizing of MDI Child Forms
Question: Do you battle with the sizing of child forms in an MDI application? I like my forms to size themselves to fit exactly within the Client area of the MParent form. Here's how.
Answer:
I use a catch all unit called VarConst.pas in all of my apps. it allows me to declare records and variables which I want to get hold of from various parts of the app. without declaring global variables. Access is controlled by adding the unit name to the Uses clause of a from in which you need to use any of the contents of VarConst.pas.
It is here that I declare a record as follows:
unit VarConstU;
interface
uses Controls, Graphics;
type
MainFormSize = record
Height: Integer;
Width: Integer;
end;
var MFS: MainFormSize;
implementation
end.
I then instatiate the record in the var section as shown above.
I add VarConst to the Uses Clause of my app. Main Form, and in the OnResize Event handler, I put the following code:
procedure TfrMain.FormResize(Sender: TObject);
begin
MFS.Height:=ClientHeight-23;
MFS.Width:=ClientWidth-4;
end;
Now, everytime I resize the Main form, MFS.Height and MFS.Width are updated. In any new MDI Child form that is opened, I put teh following code in the OnCreate Event handler:
Top:=0;
Left:=0;
Height:=MFS.Height;
Width:=MFS.Width;
The form is opened and positioned exactly the way I want it to be everytime.
Any comments or suggestions for improvement welcome.