Responding To A User Clicking The Red X In Upper Right Corner

Using VS05 Visual Basic - when a user closes a program by the red x in the upper right hand corner, is there a way to respond to that the same way as if they had properly used File, Exit

Does the X raise an event I have not been able to figure this out yet. I don't want to disable the X, just respond to it.

Thanks for your help.

Bob




Answer this question

Responding To A User Clicking The Red X In Upper Right Corner

  • sgmuser

    The reason is this is a telephony application and File|Exit waits for all calls to finish before exiting the program. The Red X simply hangs up on everyone as the program closes.

    Thanks!

    Bob



  • Whoisit

    Hi,

    you could hook into FormClosing event and check the CloseReason parameter to see why it's being closed. If it's value is "UserClosing", the user either clicked the Red X, pressed Alt-F4 or do something else that made form close... In the same event, set Cancel to True to prevent the form from closing:

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
    If e.CloseReason = CloseReason.UserClosing Then
    ' Do something
    e.Cancel = True
    End If
    End Sub

    Is there some special reason you want to detect when user pressed the Red X

    Andrej



  • Responding To A User Clicking The Red X In Upper Right Corner