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. The 'X' click event

The 'X' click event

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
7 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.
  • B Offline
    B Offline
    Brad Fackrell
    wrote on last edited by
    #1

    Does anybody know how to get the ‘X’ click event?….the ‘X’ in the upper right hand corner of a form. I want to perform a function if the ‘X’ is used to close the form (something like frmMain_ClickX) but if I use frmMain_Closing it causes certain functions to execute twice. I’m assuming that frmMain_Click is not specifically associated with the click event of the ‘X’. Thanks Brad

    V 1 Reply Last reply
    0
    • B Brad Fackrell

      Does anybody know how to get the ‘X’ click event?….the ‘X’ in the upper right hand corner of a form. I want to perform a function if the ‘X’ is used to close the form (something like frmMain_ClickX) but if I use frmMain_Closing it causes certain functions to execute twice. I’m assuming that frmMain_Click is not specifically associated with the click event of the ‘X’. Thanks Brad

      V Offline
      V Offline
      Verolix
      wrote on last edited by
      #2

      Private Sub _whatever_you_want_(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

      B 1 Reply Last reply
      0
      • V Verolix

        Private Sub _whatever_you_want_(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        B Offline
        B Offline
        Brad Fackrell
        wrote on last edited by
        #3

        I’m still a bit confused. I have the following sub that I want to be sure is executed whenever the form closes: SaveData() I have programmed the sub ‘SaveData()’ to execute under the ‘mnuExit_Click’ (and other areas). My problem is that ‘SaveData()’ is executed once when ‘mnuExit_Click’ is executed and then again during frm1_cloising. I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location. Thanks Brad

        D V 2 Replies Last reply
        0
        • B Brad Fackrell

          I’m still a bit confused. I have the following sub that I want to be sure is executed whenever the form closes: SaveData() I have programmed the sub ‘SaveData()’ to execute under the ‘mnuExit_Click’ (and other areas). My problem is that ‘SaveData()’ is executed once when ‘mnuExit_Click’ is executed and then again during frm1_cloising. I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location. Thanks Brad

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Brad Fackrell wrote: I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location. The reason why it's getting executed twice is because you execute it in the mnuExit handler AND your doing it again when the Closing event is fired. If you want to handle all possible ways of closing a form, then the Closing event is the way to go... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          B 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Brad Fackrell wrote: I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location. The reason why it's getting executed twice is because you execute it in the mnuExit handler AND your doing it again when the Closing event is fired. If you want to handle all possible ways of closing a form, then the Closing event is the way to go... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            B Offline
            B Offline
            Brad Fackrell
            wrote on last edited by
            #5

            Dave Kreskowiak wrote: If you want to handle all possible ways of closing a form, then the Closing event is the way to go... Okay. I thought that would work but then I "second guessed" myself because I thought; Why add any sub routines under mneExit? Thanks Dave.

            1 Reply Last reply
            0
            • B Brad Fackrell

              I’m still a bit confused. I have the following sub that I want to be sure is executed whenever the form closes: SaveData() I have programmed the sub ‘SaveData()’ to execute under the ‘mnuExit_Click’ (and other areas). My problem is that ‘SaveData()’ is executed once when ‘mnuExit_Click’ is executed and then again during frm1_cloising. I assume that it is bad practice to just execute ‘SaveData()’ in ‘frm1_closing’ and in no other location. Thanks Brad

              V Offline
              V Offline
              Verolix
              wrote on last edited by
              #6

              Replace SaveData() in mnuExit_Click and all other locations (except frm1_closing) by Me.Close().

              B 1 Reply Last reply
              0
              • V Verolix

                Replace SaveData() in mnuExit_Click and all other locations (except frm1_closing) by Me.Close().

                B Offline
                B Offline
                Brad Fackrell
                wrote on last edited by
                #7

                Works perfect! Thank you ;) Brad

                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