我想要做的与此相同:如何在父窗体的中心设置子窗体?
Show a child form in the centre of Parent form in C#
但在任何时刻,不仅在启动。
原因是因为我显示和隐藏表单。所以这只适用于第一场演出,因为之后它只是隐藏起来,所以我不再“启动”它。
我想要做的与此相同:如何在父窗体的中心设置子窗体?
Show a child form in the centre of Parent form in C#
但在任何时刻,不仅在启动。
原因是因为我显示和隐藏表单。所以这只适用于第一场演出,因为之后它只是隐藏起来,所以我不再“启动”它。
C#代码来显示子窗体中的该中心(这种形式是子窗体的爸爸)
frmSub fs=new frmSub();
fs.StartPosition = FormStartPosition.CenterParent;
fs.Parent = this;
fs.Show();
这会工作,但每次都会创建一个新表单,我需要只显示隐藏它 – Cher
试试这个,保持父窗体的FormBorderStyle
到FixedSingle
所以它不是调整大小。
说,假设你在button1_Click()
事件上做了这个事情,并且在事件上面声明了Form f2 = new Form();
。和子窗体的起始位置设置为CenterScreen
这样的:
f2.StartPosition = FormStartPosition.CenterScreen;
使用checkBox
可以显示/隐藏轻松子窗体。
Form f2 = new Form();
private void button1_Click(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.IsMdiContainer = true;
//Form f2 = new Form(); To prevent creating a new form everytime.
f2.MdiParent = this;
f2.StartPosition = FormStartPosition.CenterScreen;
if (checkBox1.Checked)
f2.Hide();
else
f2.Show();
}
'如果(ParentForm!= NULL) 位置=新的点((ParentForm.Size.Width - Size.Width)/ 2,(ParentForm.Size.Height - Size.Height)/ 2);' –
我看,有没有内置函数? – Cher
我怀疑是否有单行表达式的函数。 –