C# 从应用程序中的任何位置显示隐藏表单
我有几张表格 让我们把它们称为C# 从应用程序中的任何位置显示隐藏表单,c#,winforms,C#,Winforms,我有几张表格 让我们把它们称为indexForm,formOne,formTwo,formThree等等 在indexForm上,有一个按钮转到formOne,该按钮包含以下代码位: private void buttonOpenFormOne_Click(object sender, EventArgs e) { formOne displayformOne = new formOne(); displayformOne.Show
indexForm
,formOne
,formTwo
,formThree
等等
在indexForm
上,有一个按钮转到formOne
,该按钮包含以下代码位:
private void buttonOpenFormOne_Click(object sender, EventArgs e)
{
formOne displayformOne = new formOne();
displayformOne.Show();
this.Hide();
}
要从formOne
返回到indexForm
,我只需执行以下操作:
private void buttonGoBack_Click(object sender, EventArgs e)
{
indexForm displayIndexForm = new indexForm();
displayIndexForm.Show();
this.Close();
}
现在,如果我从indexForm
转到formOne
,这个功能就可以完美运行了。因此,切换回indexForm
是轻而易举的事。但是,如果我从formOne
转到formTwo
,例如,单击按钮时,indexForm
不会显示
我的问题是,如何才能从应用程序的任何位置全局返回到indexForm
,或者从应用程序的任何位置显示最初隐藏的indexForm
试试这个
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
if (frm.Name == "FormName")
{
frm.Show();
frm.BringToFront();
}
}
@Grantwiney,我如何在不创建新实例的情况下切换回原始indexForm,以及如何显示隐藏的实例?@Grantwiney好的。比如说我在二年级,从一年级开始。如何显示隐藏索引表单?创建子表单时,将其父属性设置为当前表单
displayformOne.Parent=this代码>然后,子窗体可以访问父窗体并可以重新显示它。您知道将有多少子窗体吗?@RadioSpace Yes。子窗体的数量是可确定的。