2 Replies - 356 Views - Last Post: 04 September 2009 - 01:27 PM

#1 sharpy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 38
  • View blog
  • Posts: 396
  • Joined: 02-June 07

Detect form Closing and Alarm

Posted 23 December 2007 - 11:58 AM

Description: Just copy and paste the code. My example also uses a button for closing the application.This snippet stops the form being closed when the red X is pressed. It will ask the user if they really want to close the application. It can also be used in conjuntion with a button.
'Close the app with a button
    Private Sub Quit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Quit.Click
        Application.Exit()
    End Sub

    'Detect form closing event
    Private Sub form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        'Stops the form from being closed.
        If e.CloseReason = CloseReason.UserClosing Then
            Dim answer As Object
            answer = MessageBox.Show("Are you sure you want to Exit the Application", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
            If answer = MsgBoxResult.Cancel Then e.Cancel = True
        Else
            Application.Exit()

        End If

    End Sub

This post has been edited by AdamSpeight2008: 11 January 2015 - 07:41 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Detect form Closing and Alarm

#2 Stefan57   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-May 09

Re: Detect form Closing and Alarm

Posted 23 May 2009 - 11:49 PM

This works great. I used same features in VB6 and now just started to learn VB.NET and found this :-)
Was This Post Helpful? 0
  • +
  • -

#3 jayer89   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 26-August 09

Re: Detect form Closing and Alarm

Posted 04 September 2009 - 01:27 PM

i have this code here
Private Sub Quit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WebBrowser1 close.Click()
        Application.Exit()
    End Sub
and were it says close it says it is '.'expected any help would be helpfull thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1