在现有表单中打开新表单

时间:2014-01-16 10:07:42

标签: c# winforms

我的主要表单是我的应用程序。 现在,当我打开一个新表格说显示设置。

 FormB bForm = new FormB(this);                
 blpForm.Show();               

现在这种方法很好但是表格b是一个较小的形式,它出现在我原始形式的边界之外。我不希望它是原始形式的“内部”我只是希望它的初始位置成为原始形式的中心。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

您必须自己设置其位置,这意味着您还必须将其StartPosition设置为手动。这是根据来电者的位置和大小以及对话的大小来计算对话位置的基本算法。

答案 1 :(得分:0)

这段代码怎么样?正如Rotem所说here

FormB bForm = new FormB ();
bForm .StartPosition = FormStartPosition.Manual;
bForm .Location = new Point(this.Location.X + (this.Width - bForm.Width) / 2,       
   this.Location.Y + (this.Height - bForm.Height) / 2); //this is just an example , you can customize the location
bForm .Show();
相关问题