C#里面的多窗体问题,有两个窗体Form1,Form2,准备在Form1上的BUTTON1点击Form2弹出来并同时关闭Form1,public Form1 ZhuJieMian;public Form2 GuYuan ;声明了两个窗体的量ZhuJieMian,GuYuan
private void Form1_Load(object sender, EventArgs e)
{
ZhuJieMian = new Form1();
GuYuan = new Form2();
ZhuJieMian.button1.Text = "显示 FORM2 并 关闭 FORM1";
} private void button1_Click(object sender, EventArgs e)
{
GuYuan.Show();
ZhuJieMian.Close();
}
为什么弹出Form2的时候Form1关闭不掉啊!!!我看不出错在哪里?
private void Form1_Load(object sender, EventArgs e)
{
ZhuJieMian = new Form1();
GuYuan = new Form2();
ZhuJieMian.button1.Text = "显示 FORM2 并 关闭 FORM1";
} private void button1_Click(object sender, EventArgs e)
{
GuYuan.Show();
ZhuJieMian.Close();
}
为什么弹出Form2的时候Form1关闭不掉啊!!!我看不出错在哪里?
在frmmain添加变量生命和构造函数,private frmmain form;
public frmmain(frmmain form)
{
InitializeComponent();
this.form =form;
this.form .Visible =false;
}
最后在closing事件中添加
private void frmmain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.form.Visible=true;
}
{
this.button1.Text = "显示 FORM2 并 关闭 FORM1";
} private void button1_Click(object sender, EventArgs e)
{
GuYuan = new Form2();
this.Close();
GuYuan.Show();
}
你关闭是的ZhuJieMian,form1怎么能关闭的了呢?你要关闭form1就只能用this.close()