Show a Child Form in the Centre of Parent Form in C#

Show a child form in the centre of Parent form in C#

Try:

loginForm.StartPosition = FormStartPosition.CenterParent;
loginForm.ShowDialog(this);

Of course the child form will now be a blocking form (dialog) of the parent window, if that isn't desired then just replace ShowDialog with Show..

loginForm.Show(this);

You will still need to specify the StartPosition though.

Trouble Getting Child Form to Center to Maximized Parent

You can get the parent form in the child form, and set the parent location to the child and then center it.

Location = parentForm.Location;
CenterToScreen();

You can send the parent form in the constructor.

new PasswordCheckForm(this);


Related Topics



Leave a reply



Submit