关于WinForm的简单问题.
在一个工程中定义了两个Form:Form1,Form2.
在Form1中:
if(a)
{
Form2 NewForm=new Form2();
NewForm.Show();
}
现在我需要Form2弹出来,Form1消失怎么办?(现在比较郁闷的就是运行后两个界面都在.)
------解决方案--------------------this.hidden();
------解决方案--------------------在Form1中添加如下的代码:
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Thread thread = new Thread(this.showform2);
thread.Start();
}
void showform2()
{
Application.Run(new Form2());
}
在Form2中添加如下的代码:
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Thread thread = new Thread(this.showform1);
thread.Start();
}
void showform1()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Thread thread = new Thread(this.showform2);
thread.Start();
}
void showform2()
{
Application.Run(new Form2());
}