Results 1 to 15 of 15

Thread: [RESOLVED] form close button

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2012
    Posts
    440

    Resolved [RESOLVED] form close button

    I want to preform a check before my form is closed.

    how can I do this when a user hits Alt + F4 or clicks the close button on my form?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: form close button

    When a form is about to close, it raises its FormClosing event. You can handle that event and perform whatever actions you need to perform. To prevent the form closing, just set e.Cancel to True. Just be careful that you don't prevent Windows exiting as a result. The e.CloseReason property can tell you why the form is closing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Angry Re: form close button

    yes, i have tested your way, but i saw some problem, hic!!!

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: form close button

    Quote Originally Posted by skyman2610 View Post
    yes, i have tested your way, but i saw some problem, hic!!!
    Yes, the problem is on line 12.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: form close button

    Are you sure? I was thinking it was line 8...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: form close button

    Quote Originally Posted by techgnome View Post
    Are you sure? I was thinking it was line 8...
    Well, there's a minor issue there as well but at least we both saw some problems with the code that was never posted.

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

    Re: form close button

    I dont get it, I'm only seeing 6 lines of code
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

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

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: form close button

    Quote Originally Posted by skyman2610 View Post
    yes, i have tested your way, but i saw some problem, hic!!!
    In case you missed it, JA and tg are suggesting that you should post your code because if have no idea what your code even looks like then the chances of our determining what the problem is and fixing it is pretty much nil.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2012
    Posts
    440

    Re: form close button

    I had no code as I wasn't sure how to start, your reply was helpful. Others, well perhaps a more more social interaction with others is in need

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] form close button

    Uh-huh... ok...
    "yes, i have tested your way, but i saw some problem, hic!!!" <--- this implied you had tried some code and it didn't work...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: form close button

    Quote Originally Posted by ubkra View Post
    I had no code as I wasn't sure how to start, your reply was helpful. Others, well perhaps a more more social interaction with others is in need
    You said that you had tested and saw a problem but if you had no code then how could you have tested? It may not seem like a big deal to those who post a question now and again but those of us who answer lots of questions every day have to wade through a morass of poorly worded posts. Posts that ask for help with code that they do not provide are common and frustrating.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2012
    Posts
    440

    Re: [RESOLVED] form close button

    Quote Originally Posted by ubkra View Post
    I want to preform a check before my form is closed.

    how can I do this when a user hits Alt + F4 or clicks the close button on my form?
    Sorry where did I say I had tested my code?

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] form close button

    Quote Originally Posted by ubkra View Post
    Sorry where did I say I had tested my code?
    I just realised that post #3 was made under a different account. From the apparent manner of the post I assumed that it was made by the OP, i.e. you. Was that you logged in under a different account? If not then I apologise for my incorrect assumption.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2012
    Posts
    440

    Re: [RESOLVED] form close button

    all good, thanks for your original help

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] form close button

    Sorry ubkra, technome and my own reply wasn't aimed towards you but to skyman2610 who said that he had some problems with it but never expanded on what the problem was and didn't post any code. I think jmcilhinney just mixed up your question with skyman2610's reply, that's one of the thing that can happen when somebody hijacks someone else's thread.

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