Sub MainForm_MouseClicked (EventData As MouseEvent)
Dim frm2 As Form
frm2.Initialize("frm2", 500, 500)
frm2.Show
SetFormInCenter(MainForm, frm2)
End Sub
Sub SetFormInCenter(Parent As Form, Form As Form)
Form.WindowTop = Parent.WindowTop + (Parent.WindowHeight - Form.WindowHeight) / 2
Form.WindowLeft = Parent.WindowLeft + (Parent.WindowWidth - Form.WindowWidth) / 2
End Sub
But, when using Form.ShowAndWait, one has to close the second form once and open again to center to its parent.
Is there any way we can center second form to parent (everytime) while using Form.ShowAndWait?
Try performing the position adjustment before calling ShowAndWait:
B4X:
Sub MainForm_MouseClicked (EventData As MouseEvent)
Dim frm2 As Form
frm2.Initialize("frm2", 500, 500)
SetFormInCenter(MainForm, frm2)
frm2.ShowAndWait
End Sub
I don't recommend using ShowAndWait. Real modal forms or dialogs are a thing of the past. Use Wait For as done with B4XDialogs. Or just use B4XDialogs with a custom layout.
I don't recommend using ShowAndWait. Real modal forms or dialogs are a thing of the past. Use Wait For as done with B4XDialogs. Or just use B4XDialogs with a custom layout.
I don't recommend using ShowAndWait. Real modal forms or dialogs are a thing of the past. Use Wait For as done with B4XDialogs. Or just use B4XDialogs with a custom layout.