Results 1 to 4 of 4

Thread: Problem with hiding/closing forms?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2011
    Posts
    57

    Problem with hiding/closing forms?

    Hello, I've created a program with a login form. Once you log in, the login form should close and the next form should display... my problem is...

    If I use Me.Close()... than both forms close and the application terminates.

    If I use Me.Hide()... than the application never unloads from memory and run indefinitely.

    So what do I do? Neither of these work how I need them to.

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

    Re: Problem with hiding/closing forms?

    I'll wager that you have set the login form as the startup form for the project. That is your mistake. Follow the CodeBank link in my signature and check out my WinForms Login thread for the proper way to go about it.
    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
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: Problem with hiding/closing forms?

    Quote Originally Posted by jmcilhinney View Post
    I'll wager that you have set the login form as the startup form for the project. That is your mistake. Follow the CodeBank link in my signature and check out my WinForms Login thread for the proper way to go about it.
    i'll wager that you're wrong

    i'd say the OP has as you guessed set the login form as the startup form for the project, + also has Shutdown Mode set to When startup form closes.

    all you need to do is change Shutdown Mode to When last form closes, then you can keep your login form as startup form, open the new form + close the startup form + it won't terminate.

    Project-->Properties-->Application-->Shutdown Mode

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

    Re: Problem with hiding/closing forms?

    Quote Originally Posted by .paul. View Post
    i'll wager that you're wrong

    i'd say the OP has as you guessed set the login form as the startup form for the project, + also has Shutdown Mode set to When startup form closes.

    all you need to do is change Shutdown Mode to When last form closes, then you can keep your login form as startup form, open the new form + close the startup form + it won't terminate.

    Project-->Properties-->Application-->Shutdown Mode
    That is an alternative but not one that I would recommend. Let's say that the OP does as you suggest and then they have their main form open and a second form also. It would be reasonable to expect that closing the main form would exit the application but in that case it will not.

    Ideally, the main form should be the startup form and there's no reason to deviate from that here. Changing the Shutdown Mode is primarily for when you are creating a dialogue-based, i.e. wizard-style, application. If the main form is the startup form then the app will exit when the main form is closed, regardless of anything else, which is normal application behaviour.
    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

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