Manage fsMDIChild window layout in Delphi

How to control the placement of the MDI child window (FormStyle: = fsMDIChild) in Delphi or C ++ Builder? I know that I can set Left, Top, Position, etc., But for the MDI child, in particular, they do not take effect only after the window has already been created and shown in its default location. As a result, several windows are created and positioned at once, which leads to good flickering, since windows are created in their default positions, and then they are immediately moved and changed.

Based on the VCL source, the only solution I could find was to override the TCustomForm CreateParams method and change the X, Y, Width, and Height fields of the Params parameter, but this seems like a hack. Is there a cleaner way to do this?

+2
source share
2 answers

I don’t see flickering at all, but this may be due to the fact that my computer is too fast or it may be an improvement in Windows 7 to reduce flicker.

I set the position of the MDI child window in FormShow:

procedure TForm2.FormShow(Sender: TObject); begin Top := 200; Left := 400; end; 
+1
source

You can send WM_SETREDRAW messages to the MainForm ClientHandle, one with the wParam parameter set to False and then setting wParam to True to avoid flickering when setting up the MDI child window, for example:

Delphi:

 SendMessage(Application.MainForm.ClientHandle, WM_SETREDRAW, False, 0); try Child := TChildForm.Create(Self); Child.Left := ...; Child.Top := ...; Child.Show; finally SendMessage(Application.MainForm.ClientHandle, WM_SETREDRAW, True, 0); InvalidateRect(Application.MainForm.ClientHandle, nil, True); end; 

C ++:

 SendMessage(Application->MainForm->ClientHandle, WM_SETREDRAW, FALSE, 0); try { Child = new TChildForm(this); Child->Left = ...; Child->Top = ...; Child->Show(); } __finally { SendMessage(Application->MainForm->ClientHandle, WM_SETREDRAW, TRUE, 0); InvalidateRect(Application->MainForm->ClientHandle, NULL, TRUE); } 
+2
source

Source: https://habr.com/ru/post/1307545/


All Articles