2
I have an application that works as follows: There is a main form and I open "children" forms during execution, for registration, research, etc. The intention is to always open the child forms in the center of the main form, regardless of the size of the form. For this use the following procedure (in the onCreate of the child form):
formulario->Left=(formPrincipal->pnlPrincipal->Width/2);
formulario->Top=(formPrincipal->pnlPrincipal->Height/2)-(formulario->Height/2);
Until the right moment, the form is centered correctly, as shown in the following image:
When closing the child form, restoring the main form and reopening the child form, the following problem occurs:
The child form is generated at the position that was generated the first time (with the window maximized).
One of the reasons was that of onCreate itself, but the problem wasn’t just that. I was taking as a reference the size of a panel. To solve the problem I started using the size of the form as reference, I started using the code in onShow and changed the property Position do form filho ara poDefault.
– Jeferson Leonardo
@Jefersonleonardo I even thought to suggest this, but you had mentioned that the first time the form was positioned correctly, so I didn’t quote it. The
position
of form son shouldn’t bepoMainFormCenter
?– stderr
At first it had worked well with poDefault I’ll redo some tests here. Thank you.
– Jeferson Leonardo
So I did some research and testing. To get to what I wanted I didn’t even need this code done in onShow. The position of the child form did not update when it was closed and started again because, for this, it is necessary to destroy the form and recreate it. And the position property of the child form must be poMainFormCenter
– Jeferson Leonardo
@Jefersonleonardo Since that’s what you solved, post it as an answer and accept it. Maybe it helps other people with similar problems. :)
– stderr