C#跨窗体操作(引用传递)实例代码
效果描述:
有三个窗体然后顺序分别是
(1)点击第一个窗体中的按钮弹出第二个窗体,隐藏第一个窗体
(2)第二个窗体到一定时间弹出第三个窗体
(3)点击第三个窗体的按钮关闭第三个和第二个窗体,弹出第一个窗体
From1
usingSystem;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
privatevoid打开form2隐藏form1_Click(objectsender,EventArgse)
{
Form2f=newForm2();
f.fatherForm=this;
f.Show();
this.Hide();
}
}
}
Form2
usingSystem;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm2:Form
{
publicForm2()
{
InitializeComponent();
}
publicForm1fatherForm;
privatevoid打开from3_Click(objectsender,EventArgse)
{
Form3f=newForm3();
f.fatherForm=this;
f.Show();
}
}
}
Form3
usingSystem;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm3:Form
{
publicForm3()
{
InitializeComponent();
}
publicForm2fatherForm;
privatevoid关闭form3from2显示from1_Click(objectsender,EventArgse)
{
fatherForm.fatherForm.Show();
fatherForm.Close();
this.Close();
}
}
}
相关文章