Form1有一个按钮如果我们单击该按钮它将显示另一个窗体(Form2) [英] Form1 had one button if we click that button it wil show another form(Form2)
本文介绍了Form1有一个按钮如果我们单击该按钮它将显示另一个窗体(Form2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是,当我们点击按钮时,前一个表单2将被关闭,新的form2应该打开如何在Windows窗体中编写代码
and my question is when ever we click on button previous form 2 be closed and new form2 should be open how to write code in windows forms
推荐答案
试试这个:
Try this:
Form2 currentActiveForm2 = null;
void yourButton_Click(object sender, EventArgs e)
{
if (currentActiveForm2 != null)
{
currentActiveForm2.Close();
// if currentActiveForm2 is null, your button has not been clicked yet, so the form doesn't exist yet and we cannot close it.
}
currentActiveForm2 = new Form2();
currentActiveForm2.Show();
}
这篇关于Form1有一个按钮如果我们单击该按钮它将显示另一个窗体(Form2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文