from1的打开新窗体事件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As New Form2 frm.Show() Me.Dispose(False) '主代码 End Sub想要那个窗体关闭主程序就在那个窗体写 Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Application.Exit() End Sub
fr.ShowDialog();
this.Visiable=False;
然后showdialog新窗体。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
frm.Show()
Me.Dispose(False) '主代码
End Sub想要那个窗体关闭主程序就在那个窗体写
Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Application.Exit()
End Sub
form1(弹出)的close事件中
Application.Exit();
主窗体隐藏也没问题,可是在弹出窗体上如何关闭隐藏的主窗体和这个弹出窗体啊
Dispose both?
主窗体出现---隐藏主窗体----弹出Form2窗体---调用Application.Exit();推出
class form2
{
public form2()
{ }
//
private test()
{
if(true)// 条件自己决定
{
form1 newform1 = new form1();
this.close();
}
else
{
//false
}
}
main()
{
form2 newform2 = new form2();
}
}
static void Main()
{
Application.Run(new Form1());
Application.Run(new Form2());
}
{
Application.Run(new Form1());
Application.Run(new Form2()); //关闭第一个窗口后自动显示第二个 窗口
}
Form1 fr=new Form1();
this.Visible=false;
//实例化窗体二,并显示。
Form2 frm2 = new Form2();
frm2.Show();
........
//关闭所有程序。
Application.Exit();这样就可以了。呵呵。
this.Hide();
form2.Show();private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
然后在Main方法里写个判断式是closed 为假的话就Application.Exit();
在form1的构造函数里写
Form2 fr=new Form2();
fr.ShowDialog();//在构造form1时先把form2构造出来
form2退出时 如果需要让form1显示出来 把closed弄为真
就ok了
这方法很好用