C#的窗体关闭\隐藏\显示问题
我有三个窗体然后顺序分别是(1)点击第一个窗体中的按钮弹出第二个窗体,隐藏第一个窗体(2)第二个窗体到一定时间弹出第三个窗体(3)点击第三个窗体的按钮关闭第三个和第二个窗...
我有三个窗体
然后顺序分别是
(1)点击第一个窗体中的按钮弹出第二个窗体,隐藏第一个窗体
(2)第二个窗体到一定时间弹出第三个窗体
(3)点击第三个窗体的按钮关闭第三个和第二个窗体,弹出第一个窗体
现在的问题是,我想实现(3),可是第二个窗体关不了,这是什么回事,代码应该怎么写呢? 展开
然后顺序分别是
(1)点击第一个窗体中的按钮弹出第二个窗体,隐藏第一个窗体
(2)第二个窗体到一定时间弹出第三个窗体
(3)点击第三个窗体的按钮关闭第三个和第二个窗体,弹出第一个窗体
现在的问题是,我想实现(3),可是第二个窗体关不了,这是什么回事,代码应该怎么写呢? 展开
2个回答
展开全部
form1
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开form2隐藏form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.fatherForm = this;
f.Show();
this.Hide();
}
}
}
form2
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form1 fatherForm;
private void 打开from3_Click(object sender, EventArgs e)
{
Form3 f = new Form3();
f.fatherForm = this;
f.Show();
}
}
}
form3
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public Form2 fatherForm;
private void 关闭form3from2显示from1_Click(object sender, EventArgs e)
{
fatherForm.fatherForm.Show();
fatherForm.Close();
this.Close();
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开form2隐藏form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.fatherForm = this;
f.Show();
this.Hide();
}
}
}
form2
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form1 fatherForm;
private void 打开from3_Click(object sender, EventArgs e)
{
Form3 f = new Form3();
f.fatherForm = this;
f.Show();
}
}
}
form3
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public Form2 fatherForm;
private void 关闭form3from2显示from1_Click(object sender, EventArgs e)
{
fatherForm.fatherForm.Show();
fatherForm.Close();
this.Close();
}
}
}
展开全部
编程代码:
form1
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开form2隐藏form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.fatherForm = this;
f.Show();
this.Hide();
}
}
}
form2
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form1 fatherForm;
private void 打开from3_Click(object sender, EventArgs e)
{
Form3 f = new Form3();
f.fatherForm = this;
f.Show();
}
}
}
form3
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public Form2 fatherForm;
private void 关闭form3from2显示from1_Click(object sender, EventArgs e)
{
fatherForm.fatherForm.Show();
fatherForm.Close();
this.Close();
}
}
}
提示:
用模式对话框ShowDialog()
关闭时返回this.DialogResult = DialogResult.值;
主窗体按键代码:
form1 f = new form1();
this.Hide();
DialogResult d = f.ShowDialog();
if(d == DialogResult.值)
this.visable = true;
form1
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开form2隐藏form1_Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.fatherForm = this;
f.Show();
this.Hide();
}
}
}
form2
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form1 fatherForm;
private void 打开from3_Click(object sender, EventArgs e)
{
Form3 f = new Form3();
f.fatherForm = this;
f.Show();
}
}
}
form3
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public Form2 fatherForm;
private void 关闭form3from2显示from1_Click(object sender, EventArgs e)
{
fatherForm.fatherForm.Show();
fatherForm.Close();
this.Close();
}
}
}
提示:
用模式对话框ShowDialog()
关闭时返回this.DialogResult = DialogResult.值;
主窗体按键代码:
form1 f = new form1();
this.Hide();
DialogResult d = f.ShowDialog();
if(d == DialogResult.值)
this.visable = true;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询