Guyz, I want to know about the Form Disposed Event. I want that everytime I click the close button ("red X button located at the top right of the form") there will be a message box that asking if I want to exit, then if I click yes the programs ends then if I click No then nothing happens. I also call a function that deactivates the state of the User when I click Yes. The problem is when I click NO, the message box appears but the form has been disposed and the function I called was not execute..How will I do this? Help me guyz...
Here's my script...

Private Sub frmMain_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        If MsgBox("Are you sure you want to exit?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Exit") = MsgBoxResult.Yes Then
            Call inactive()
            Application.Exit()
        Else
    
        End If

Recommended Answers

All 2 Replies

Handle formClosing event instead of disposed.

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MsgBox("Are you sure you want to exit?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Exit") = MsgBoxResult.No Then
            e.Cancel = True
        End If
    End Sub

thanx a lot sir! you never let me down...
as always >>> Lee ^_^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.