C#.net Winform -Multiple forms show&隐藏

时间:2012-02-29 15:28:02

标签: forms window hide show

我在visual studio 2008中使用c#.net获取了3个表单。在Form1中有2个按钮,如果我点击第一个按钮,那么Form2将显示&同时我点击了第二个按钮,然后Form3将显示&已打开的Form2将隐藏。

1 个答案:

答案 0 :(得分:2)

//loop through all open forms
foreach (Form f in Application.OpenForms)
{
    if (f.Name != "Form1") //if it's not Form1
        f.Hide(); //then hide it (or close)
}
//show the form you want (ex: Form3)
new Form3().Show();