Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with FormClosing event

Problem with FormClosing event

Scheduled Pinned Locked Moved Visual Basic
questionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yosh_
    wrote on last edited by
    #1

    Hi Guys, Every time I try to verify if the user wants to exit the app, the question box comes out twice. I do it like this: Private Sub Register_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim exitChoice As Windows.Forms.DialogResult exitChoice = MessageBox.Show("Are you sure you want to exit?", "Exiting?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) If exitChoice = Windows.Forms.DialogResult.Yes Then Application.Exit() Else e.Cancel = True End If End Sub It comes out twice even if yes is clicked the first time. How do i make it come out only once?

    He who goes for revenge must first dig two graves.

    T 1 Reply Last reply
    0
    • Y Yosh_

      Hi Guys, Every time I try to verify if the user wants to exit the app, the question box comes out twice. I do it like this: Private Sub Register_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim exitChoice As Windows.Forms.DialogResult exitChoice = MessageBox.Show("Are you sure you want to exit?", "Exiting?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) If exitChoice = Windows.Forms.DialogResult.Yes Then Application.Exit() Else e.Cancel = True End If End Sub It comes out twice even if yes is clicked the first time. How do i make it come out only once?

      He who goes for revenge must first dig two graves.

      T Offline
      T Offline
      TheComputerMan
      wrote on last edited by
      #2

      The form is closing anyway so remove the application.exit (assuming this is the final form) Only do the cancel = true if they want to stay in. Private Sub Register_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim exitChoice As Windows.Forms.DialogResult exitChoice = MessageBox.Show("Are you sure you want to exit?", "Exiting?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) If exitChoice = Windows.Forms.DialogResult.No Then e.Cancel End If End Sub

      T 1 Reply Last reply
      0
      • T TheComputerMan

        The form is closing anyway so remove the application.exit (assuming this is the final form) Only do the cancel = true if they want to stay in. Private Sub Register_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim exitChoice As Windows.Forms.DialogResult exitChoice = MessageBox.Show("Are you sure you want to exit?", "Exiting?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) If exitChoice = Windows.Forms.DialogResult.No Then e.Cancel End If End Sub

        T Offline
        T Offline
        tmalbon
        wrote on last edited by
        #3

        ' you need to add the following code to fix it ' on the same file where your Register_FormClosing is, declare this Private if_already_close As Integer ' inside your Register_FormClosing, add ' before Dim exitChoice If if_already_close <> 1234 Then if_already_close = 1234 ' your MessageBox.Show(...) codes here End If ' before the End Sub

        TMALBONPH

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups