Results 1 to 11 of 11

Thread: Closing form

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Resolved Closing form

    I have moved from vb6 and being only a beginner of vb6 but understanding somewhat the basics, I am having trouble with 2010 and the new code.

    When someone clicks the button I generally would add to load the form then followed by the unload me.

    So where am I going wrong in 2010?

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Form1.Show()
            Me.Close()
        End Sub
    I tried the unload me, thats not even an option, adds some other weird stuff, so I googled and tried the me.close but thats not it either.

    Thanks.
    Last edited by jokerfool; Nov 20th, 2010 at 11:01 AM.

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

    Re: Closing form

    First up, why exactly do you want to close the current form? There may be a legitimate reason but then again there may well not. The fact that you're trying to show Form1 suggests that the current form is being displayed before the main form. If that is the case then you certainly shouldn't be doing it like that. Perhaps you should explain EXACTLY what you're trying to achieve and then we can explain the best way to achieve it.

    Having said that, if there is a legitimate reason for doing things that way then it's a simple matter of change a selection in a drop-down in the project properties. By default, the application exits when you close the main form. If you want a wizard-style application, where you move from form to form, then you need to change the shutdown mode in the project properties to when the last form closes.
    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

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Closing form

    Okay coming from vb6 to 2010 there is a lot I need to learn and it already looks like so much has changed that alot of vb6 I should just forget.

    Your comment totally confused me.

    The slashscreen loads, I want to setup a progress bar that loads for e.g. 10 seconds then closes and displays the next form closing the splash screen but for now I have a button on the splash screen so that loads, user clicks button, slash screen closes and loads form1.

    Thanks

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

    Re: Closing form

    Quote Originally Posted by jokerfool View Post
    Okay coming from vb6 to 2010 there is a lot I need to learn and it already looks like so much has changed that alot of vb6 I should just forget.
    You should forget everything. VB.NET syntax is based on VB6 syntax but it is a new language written from the ground up. Learn it like a new language and just consider it a bonus when something turns out to work the same as it did in VB6.
    Quote Originally Posted by jokerfool View Post
    The slashscreen loads, I want to setup a progress bar that loads for e.g. 10 seconds then closes and displays the next form closing the splash screen but for now I have a button on the splash screen so that loads, user clicks button, slash screen closes and loads form1.
    As I suspected, there's no reason for you to be hiding one form and showing another like that at all. As it stands, you've got a splash screen and you have selected that as your startup form, then you have the splash screen closing itself and showing the main form. That's all wrong.

    What you should be doing is selecting your main form as the startup form and selecting your splash screen as the splash screen. Open the Application page of the project properties and you'll find a drop-down for each. You simply select the two forms in the appropriate drop-downs and the system does the rest. The splash screen will be displayed first and it will remain on screen for the minimum time or as long as it takes for the main form to load, whichever is longer. By default, the minimum display time for the splash screen is two seconds, but you can change that if you want.

    http://msdn.microsoft.com/en-us/libr...8VS.90%29.aspx

    I would strongly advise against forcing your splash screen to stay open for 10 seconds. If that's how long it takes the main form to load then so be it, but there's no point making the user wait that long if they don't have to. Two or three seconds staring at a splash screen is quite enough.
    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

  5. #5
    Member
    Join Date
    Oct 2010
    Posts
    42

    Re: Closing form

    Use Form1.Show()
    Me.Hide()

  6. #6
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Closing form

    Me.Hide instead of close

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

    Re: Closing form

    Quote Originally Posted by hectorcuper View Post
    Use Form1.Show()
    Me.Hide()
    Quote Originally Posted by salmawy View Post
    Me.Hide instead of close
    Those hacks rather than solutions and they are completely unnecessary. If you do that then you've got this splash screen hanging around the whole time the application is open. If you do things properly in the first place then you don't need hacks.
    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

  8. #8
    Member
    Join Date
    Oct 2010
    Posts
    42

    Re: Closing form

    Splash screen? i never had that problem.
    I do use a different method now though, i just let it minimize the startup window (or send it to tray) and after that, you can use close on any other form, without the whole program shutting down.

  9. #9

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Closing form

    jmcilhinney I suspected that alot had changed so I will definitely go with your instructions and learn this way rather than what you mentioned above. I didn't realise VB6 was totally left behind and 2010 had so many new features which I have only just discovered about 2%. I will get back to you if I have more questions and get stuck. Thank you.

  10. #10
    Member srspiewarmer's Avatar
    Join Date
    Oct 2010
    Location
    Manila, Philippines.
    Posts
    58

    Re: Closing form

    vb Code:
    1. Private Sub YourForm_Closing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YourForm.Closing
    2.  
    3.         Form1.Show()
    4.  
    5.     End Sub

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

    Re: Closing form

    VB 2010 is the fifth version of VB.NET, with the first having been released back in 2002. VB 2010 and .NET 4.0 have tons of new stuff even compared to VB.NET 2002 and .NET 1.0, which themselves were a big departure from VB6 and COM.
    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