Results 1 to 16 of 16

Thread: The "X" Button

Hybrid View

  1. #1
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: The "X" Button

    Quote Originally Posted by weirddemon View Post
    FormClosing. You can e.Cancel = True, clean up, and the call Me.Close

    Though you may not have to cancel the close. You'll need to play around with it to see what's best.
    This doesn't make any sense. If you set e.Cancel to true (which takes effect after the sub has finished) and you call me.Close from inside of it, you're going to get the FormClosing event raised again, where you're setting e.Cancel to True all over again. It'd never let the form close.

    What you should do is set e.Cancel to True under 2 conditions: you've prompted the user for confirmation and they choose the cancel the form's close or something fails during the cleanup process and you want to keep the form open a little longer to let the user try closing it again later.

    Also, when canceling the FormClosing event, always let the form close if: Windows is shutting down, or the user kills the app from the Taskmanager. Both of these can be tested for under e.CloseReason
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: The "X" Button

    Quote Originally Posted by JuggaloBrotha View Post
    This doesn't make any sense. If you set e.Cancel to true (which takes effect after the sub has finished) and you call me.Close from inside of it, you're going to get the FormClosing event raised again, where you're setting e.Cancel to True all over again. It'd never let the form close.

    What you should do is set e.Cancel to True under 2 conditions: you've prompted the user for confirmation and they choose the cancel the form's close or something fails during the cleanup process and you want to keep the form open a little longer to let the user try closing it again later.

    Also, when canceling the FormClosing event, always let the form close if: Windows is shutting down, or the user kills the app from the Taskmanager. Both of these can be tested for under e.CloseReason
    I thought checking for conditions would be implied.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width