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

后端 未结 19 1046
不思量自难忘°
不思量自难忘° 2020-11-28 08:21

I create a new form and call from the parent form as follows:

loginForm = new SubLogin();   
loginForm.Show();

I need to display the chi

相关标签:
19条回答
  • 2020-11-28 09:12

    If you want to calculate your own location, then first set StartPosition to FormStartPosition.Manual:

    Form Child = new Form();
    Child.StartPosition = FormStartPosition.Manual;
    Child.Location = new Point(Location.X + (Width - Child.Width) / 2, Location.Y + (Height - Child.Height) / 2);
    Child.Show(this);
    

    Where this is the main/parent form, just like Location.X.

    Default value for StartPosition is FormStartPosition.CenterParent and therefore it changes the child's location after showing.

    0 讨论(0)
提交回复
热议问题