Me.Close does not work

前端 未结 3 856
野的像风
野的像风 2021-01-19 01:57

I\'m working with VB.net. I’m having problems while I connect my application to my database today so I wanted to add an error handling to close the form.

The problem

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-19 02:29

    You can check for what reason the form don't get closed.

    Private Sub Form1_Closing(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles MyBase.FormClosing
    
       MsgBox(e.CloseReason.ToString)
    
    End Sub
    

    You can add to the Form_Closing event the following The e.Cancel will close the open operation. But first check the reason.

    Private Sub Form1_Closing(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles MyBase.FormClosing
    
      e.Cancel = True
    
    End Sub
    

提交回复
热议问题