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

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

    It works in all cases, swap Form1 for your main form.

    Popup popup = new Popup();
    popup.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
    popup.Location = new System.Drawing.Point((Form1.ActiveForm.Location.X + Form1.ActiveForm.Width / 2) - (popup.Width / 2),(Form1.ActiveForm.Location.Y + Form1.ActiveForm.Height / 2) - (popup.Height / 2));
    popup.Show(Form1.ActiveForm);
    

提交回复
热议问题