在父级的中心显示对话框

在父窗体的中心显示一个DialogBox是一团糟。 这是一个显示对话框的方法。

我将其父母放置在中心位置,但无法居中对话框

private void OpenForm(Object point, Object height, Object width) { FormLoading frm = new FormLoading(); Point temp = (Point)point; Point location = new Point(temp.X + (int)((int)width) / 2, temp.Y + (int)((int)height) / 2); frm.Location = location; frm.ShowDialog(); } private void btnView_Click(object sender, EventArgs e) { try { ThreadStart starter= delegate { OpenForm(currentScreenLocation, this.Height, this.Width); }; Thread t = new Thread(starter); t.Start(); ////// Some functionality here... t.Abort(); } catch (Exception) { } } 

您可能需要检查Form.StartPosition属性。

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition.aspx

一些沿线的东西:

 private void OpenForm(Form parent) { FormLoading frm = new FormLoading(); frm.Parent = parent; frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); } 

这当然需要设置表单的父项。

 form1.StartPosition = FormStartPosition.CenterScreen; 

请参阅http://msdn.microsoft.com/zh-CN/library/system.windows.forms.form.startposition(v = vs.110).aspx

另外,如果你想设置任意位置,你可以使用这个

 FormLoading frm = new FormLoading(); Point location = new Point(300, 400); frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual; frm.Location = location; frm.ShowDialog(); 
 NewForm.Show(); NewForm.Top = (this.Top + (this.Height / 2)) - NewForm.Height / 2; NewForm.Left = (this.Left + (this.Width / 2)) - NewForm.Width / 2;