Topic: Centre Child Forms relative to Main Form

Hello All,
Some help if anyone has any ideas please.
THE PROBLEM
I have an application with a main form (Form1) and a number of child forms (see screen1 in the attachment). 
However, if I move Form1 anywhere on the monitor, then the child form is no longer centred on Form1 (see screen2 in the attachment).
WHAT I DO AT THE MOMENT
The position of the child forms is forced to be centred on Form1 with a script (see screen3 in the attachment). 
But within the procedure, the code to re-centre each child form is repeated - the more child forms, the more the code is repeated.  This is what I want to avoid.
WHAT I'M TRYING TO DO (without success!)
Create a procedure (similar to screen4 in the attachment (which obviously is incorrect at the moment)) that
1.  uses a variable ('vform') to identify the name of any child form that has just been opened and
2.  uses that variable as part of the formula to re-centre the child form.
I'm using Windows 10 / MVD 6.5.
Any ideas and help would be appreciated.
Regards,
Derek.

Post's attachments

Attachment icon centre child forms.zip 629.91 kb, 40 downloads since 2023-09-10 

Re: Centre Child Forms relative to Main Form

Дело в том, что позиция формы устанавливается только 1 раз при ее открытии.
Вам нужно устанавливать ее позицию постоянно.
 
The fact is that the position of the form is set only once when it is opened.
You need to establish its position constantly.

procedure Form1_buttonabout_OnClick (Sender: TObject; var Cancel: boolean);
begin
  FormAbout.Position := poMainFormCenter;
end;

procedure Form1_buttondelete_OnClick (Sender: TObject; var Cancel: boolean);
begin
  Form3.Position := poMainFormCenter;
end;

procedure Form1_buttonadd_OnClick (Sender: TObject; var Cancel: boolean);
begin
  Form2.Position := poMainFormCenter;
end;
Post's attachments

Attachment icon centre child forms.rar 111.07 kb, 37 downloads since 2023-09-10 

Re: Centre Child Forms relative to Main Form

Спасибо Vladimir,
Это очень помогло. Я пытался переместить "child forms" после того, как открыл их, а не раньше.
А использование "poMainFormCentre" вместо попыток вычисления позиции делает скрипт намного компактнее.
Теперь все работает как надо.
С уважением,
Derek.
.
That has helped a lot.  I was trying to move the "child forms" after I had opened them rather than before.
And using 'poMainFormCentre' instead of trying to calculate the position makes the script much more compact.
Everything works as it should now.

Post's attachments

Attachment icon centre child forms 2.zip 443.97 kb, 52 downloads since 2023-09-11