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

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

    When you want to use a non-blocking window (show() instead of showDialog()), this not work:

    //not work with .Show(this) but only with .ShowDialog(this)
    loginForm.StartPosition = FormStartPosition.CenterParent;
    loginForm.Show(this);
    

    In this case, you can use this code to center child form before display the form:

    //this = the parent
    frmDownloadPercent frm = new frmDownloadPercent();
    frm.Show(this); //this = the parent form
    //here the tips
    frm.Top = this.Top + ((this.Height / 2) - (frm.Height / 2));
    frm.Left = this.Left + ((this.Width / 2) - (frm.Width / 2));
    

提交回复
热议问题