vb.net 多层窗体关闭出现错误的问题
一共3个窗体:Form1,Form2,Form3.
Form1是启动窗体,上边一个按钮Button1,Form2上的按钮Button2,Form3上的窗体Button3.
大致代码如下:(想通过点击Button3关闭整个应用程序)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Form2.ShowDialog()End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Form3.ShowDialog()End SubPrivate Sub Form2_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing On Error GoTo showError Form1.Close()showError: MsgBox("Form1:" & ErrorToString(), MsgBoxStyle.Critical, "Form1.Close") ReturnEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickOn Error GoTo showError Me.CloseshowError: MsgBox(ErrorToString(), MsgBoxStyle.Critical, "Form3.Close") ReturnEnd SubPrivate Sub Form3_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing Form2.Close()End SubPrivate Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing ‘释放一些在Form1定义的资源End Sub