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

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

    On the SubLogin Form I would expose a SetLocation method so that you can set it from your parent form:

    public class SubLogin : Form
    {
       public void SetLocation(Point p)
       {
          this.Location = p;
       }
    } 
    

    Then, from your main form:

    loginForm = new SubLogin();   
    Point p = //do math to get point
    loginForm.SetLocation(p);
    loginForm.Show();
    

提交回复
热议问题