Re: More mdi fun
"Bisma Jayadi" <[email protected]> Tue, 18 Feb 2003 11:34:23 +0700
| Newsgroups | gmane.comp.lang.delphi.kylix |
|---|---|
| Organization | Brawijaya IT Services |
| Message-ID | <000a01c2d707$0338c430$910311ac@simba> |
Try the following code, is that the way you want?
======
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, Menus;
type
// main form is the mdi parent window
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Window1: TMenuItem;
New1: TMenuItem;
ArrangeHorz1: TMenuItem;
ArrangeVert1: TMenuItem;
procedure New1Click(Sender: TObject);
procedure ArrangeHorz1Click(Sender: TObject);
procedure ArrangeVert1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// this unit contains TForm2 as the mdi child form
uses
Unit2;
procedure TForm1.New1Click(Sender: TObject);
var
Child: TForm2;
begin
// create new child form window
Child := TForm2.Create(Application);
end;
procedure TForm1.ArrangeHorz1Click(Sender: TObject);
var
i: integer;
FrameWidth: integer;
begin
// measure form's frame width
FrameWidth := (Width - ClientWidth) div 2;
// check if there is childform available
if MDIChildCount > 0 then
for i := 0 to MDIChildCount-1 do
begin
{ arrange form(s) horizontally }
// same top and height
MDIChildren[i].Top := 0;
MDIChildren[i].Height := ClientHeight-FrameWidth;
// measure form(s)'s width
MDIChildren[i].Left := i*((ClientWidth-FrameWidth) div
MDIChildCount);
MDIChildren[i].Width := (ClientWidth-FrameWidth) div
MDIChildCount;
end;
end;
procedure TForm1.ArrangeVert1Click(Sender: TObject);
var
i: integer;
FrameWidth: integer;
begin
// measure form's frame width
FrameWidth := (Width - ClientWidth) div 2;
// check if there is childform available
if MDIChildCount > 0 then
for i := 0 to MDIChildCount-1 do
begin
{ arrange form(s) vertically }
// same left and width
MDIChildren[i].Left := 0;
MDIChildren[i].Width := ClientWidth-FrameWidth;
// measure form(s)'s height
MDIChildren[i].Top := i*((ClientHeight-FrameWidth) div
MDIChildCount);
MDIChildren[i].Height := (ClientHeight-FrameWidth) div
MDIChildCount;
end;
end;
end.
======
If you place a status bar or any components on mdi parent form which
reduce the space (height or width) for mdi child form but not decrease
the parent's ClientHeight/Width value, then you must substract the
ClientHeight/Width of the parent form with the component's
Height/Width to get the child form's position correct.
Hope this helps.
-Bee-
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.455 / Virus Database: 255 - Release Date: 13-02-2003
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/i7folB/TM
---------------------------------------------------------------------~->
-------------------------------------------------------
Forum / mailing list for Borland Kylix programmers
Our web page: http://groups.yahoo.com/group/kylixgroup
To join the forum: [email protected]
To unsubscribe: [email protected]
To post your messages: [email protected]
To contact the moderator: [email protected]
-------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/