I have used the below code but its not showing the msgbox. What is wrong with this code ?
Private Sub frmSimple_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
Dim result = MsgBox("Are you sure you want to Exit ?", vbYesNo)
If result = DialogResult.Yes Then
me.Close()
End If
End Sub
This code runs after the form has been closed, when it's being disposed.
Depending on how you're showing the form, it might not get disposed at all.
You need to handle the FormClosing
event and set e.Cancel
to True
if you want to cancel the close.
Private Sub frmProgramma_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Are you sur to close this application?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Else
e.Cancel = True
End If
End Sub
or that is how i use it everytime over and over...
Use FormClosing
event. MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With