C#窗口切换问题的解决

来源:互联网 发布:java打印所有ASCII码 编辑:程序博客网 时间:2024/06/06 04:14

 


要求 
1、单击form1窗口中按钮后,隐藏form1,显示form2窗口。 
2、单击form2窗口中按钮后,关闭form2,显示form1窗口。且form1中数据依然存在。 
源代码:
//在Form1 按钮中加入
Form2 frm=new Form2();
 
frm.MasterForm=this;//在Form2中加入MasterForm属性
 
frm.show();
this.Hide();
 
//在Form2中加入MasterForm属性和masterForm字段
 
private Form1 masterForm;
public Form1 MasterForm
{
   set    {this.masterForm=value;}
}
 
//在Form2按钮中加入
this.masterForm.Show();
this.Close();