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

后端 未结 19 1154
不思量自难忘°
不思量自难忘° 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:11

    Assuming your code is running inside your parent form, then something like this is probably what you're looking for:

    loginForm = new SubLogin();
    loginForm.StartPosition = FormStartPosition.CenterParent
    loginForm.Show(this);
    

    For the record, there's also a Form.CenterToParent() function, if you need to center it after creation for whatever reason too.

提交回复
热议问题