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 while trying to use form closing event [modified]

problem while trying to use form closing event [modified]

Scheduled Pinned Locked Moved Visual Basic
help
6 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.
  • K Offline
    K Offline
    kisran
    wrote on last edited by
    #1

    Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    Dim a As Integer
    a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
    If a = 6 Then
    'Application.Run()
    e.Cancel = False
    Else
    ' Application.Exit()
    e.Cancel = True
    End If
    End Sub

    Thanks in advance........ :doh:

    kisran

    modified on Tuesday, September 16, 2008 2:40 AM

    C G 2 Replies Last reply
    0
    • K kisran

      Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.

      Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
      Dim a As Integer
      a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
      If a = 6 Then
      'Application.Run()
      e.Cancel = False
      Else
      ' Application.Exit()
      e.Cancel = True
      End If
      End Sub

      Thanks in advance........ :doh:

      kisran

      modified on Tuesday, September 16, 2008 2:40 AM

      C Offline
      C Offline
      C1AllenS
      wrote on last edited by
      #2

      Hello Kisran, I am not sure whats wrong at your side. But your code works perfectly at my end. In case you are not able to resolve it, you can probably try this slight modified version of your code. BEGIN CODE Dim dr As DialogResult = MessageBox.Show("Do you wish to close the Form", "Closing Form", MessageBoxButtons.YesNo) If dr = Windows.Forms.DialogResult.Yes Then e.Cancel = False Else e.Cancel = True End If END CODE I hope this works. Regards, Allen

      Allen Smith ComponentOne LLC www.componentone.com

      K 1 Reply Last reply
      0
      • C C1AllenS

        Hello Kisran, I am not sure whats wrong at your side. But your code works perfectly at my end. In case you are not able to resolve it, you can probably try this slight modified version of your code. BEGIN CODE Dim dr As DialogResult = MessageBox.Show("Do you wish to close the Form", "Closing Form", MessageBoxButtons.YesNo) If dr = Windows.Forms.DialogResult.Yes Then e.Cancel = False Else e.Cancel = True End If END CODE I hope this works. Regards, Allen

        Allen Smith ComponentOne LLC www.componentone.com

        K Offline
        K Offline
        kisran
        wrote on last edited by
        #3

        Thanks allen but this still not working.......

        kisran

        1 Reply Last reply
        0
        • K kisran

          Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.

          Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
          Dim a As Integer
          a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
          If a = 6 Then
          'Application.Run()
          e.Cancel = False
          Else
          ' Application.Exit()
          e.Cancel = True
          End If
          End Sub

          Thanks in advance........ :doh:

          kisran

          modified on Tuesday, September 16, 2008 2:40 AM

          G Offline
          G Offline
          Gagan 20
          wrote on last edited by
          #4

          Try the following code : Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) dim res res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample") if res=vbno then e.cancel=false else e.cancel=true endif MyBase.OnClosing(e) Hope the above code will work...

          K 1 Reply Last reply
          0
          • G Gagan 20

            Try the following code : Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) dim res res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample") if res=vbno then e.cancel=false else e.cancel=true endif MyBase.OnClosing(e) Hope the above code will work...

            K Offline
            K Offline
            kisran
            wrote on last edited by
            #5

            Still Not working Gagan............ Its giving compile time error on MyBase.OnClosing(e)

            Error: OnClosing(e) is not a member of system.web.ui

            can you Please Help me

            kisran

            modified on Tuesday, September 16, 2008 2:39 AM

            G 1 Reply Last reply
            0
            • K kisran

              Still Not working Gagan............ Its giving compile time error on MyBase.OnClosing(e)

              Error: OnClosing(e) is not a member of system.web.ui

              can you Please Help me

              kisran

              modified on Tuesday, September 16, 2008 2:39 AM

              G Offline
              G Offline
              Gagan 20
              wrote on last edited by
              #6

              Try again this one:

              Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)

              dim res

              res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample")

              if res=vbno then

              e.cancel=false

              else

              e.cancel=true

              endif

              MyBase.OnClosing(e)

              end sub

              Put end sub after mybase.onclose(e) statement

              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