Author: Tomas Rutkauskas
Center a Form efficiently
Answer:
To center a form after having changed its dimensions at run-time,
the poScreenCenter won't do it - it only works when the form is shown.
The following code shows 2 solutions how to handle this "problem":
1 2 // this works, but the form will be redrawn two times3 // (one redraw for each assignment)4 Form1.Left := (Screen.Width div 2) - (Form.Width div 2);
5 Form1.Top := (Screen.Height div 2) - (Form.Height div 2);
6 7 // this is better.. the form is redrawn only once8 Form1.SetBounds((Screen.Width - AForm.Width) div 2,
9 (Screen.Height - AForm.Height) div 2,
10 ATop, Form1.Width, Form1.Height);