Author: Jonas Bilinkevicius
I have an MDI application with many child forms. Their windowstate property is set
to maximized. When a child form is created and shown, the form visibly resizes as
it is shown. I would like the child form to open already maximized without the
visible resizing. Any ideas?
Answer:
Preventing visible flicker when moving or sizing MDI children directly after their
creation:
1 { ... }2 public3 { Public declarations }4 5 constructor Create(aOwner: TComponent); override;
6 end;
7 8 implementation9 10 {$R *.DFM}11 12 constructor TMDIChild.Create(aOwner: TComponent);
13 var14 crect: TRect;
15 chandle: HWND;
16 begin17 { Get handle of MDI client window }18 chandle := application.mainform.clienthandle;
19 { Block redrawing of this window and its children }20 Lockwindowupdate(chandle);
21 { Create this MDI child at default position, it will not be drawn yet22 due to the update block }23 inherited Create(aOwner);
24 { Get the client windows rect and center this form in it }25 Windows.GetClientrect(chandle, crect);
26 SetBounds((crect.right - width) div 2, (crect.bottom - height) div 2, width,
27 height);
28 { Release the block, this allows the form to redraw at the new position }29 LockWindowUpdate(0);
30 end;