Results 1 to 6 of 6

Thread: Close one form and open another

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    19

    Close one form and open another

    When I open my application I have the first form which opens as the Register form. When I press the Activate Button I want the MAIN form to open and I am using the code below as the last two line:

    Main.ShowDialog()
    Me.Close()

    When the main form opens the Register form does not close and stays background.

    If I close:

    me.close()
    main.showdialog()

    then the whole application closes.

    Any help on this matter?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Close one form and open another

    Since Main.ShowDialog() would cause VB6 to yak all over itself, I suspect you are using VB.NET.

    Moved

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    19

    Re: Close one form and open another

    Yes this is Vb.Net. Am I in the wrong place?

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Close one form and open another

    Hi Mohdali, you are in the right place now! There are two things you need to change.

    First, you must use Main.Show instead of Main.ShowDialog. Otherwise, your first form can't close until after Main closes.

    Second, you need to go to the project properties, and change the Shutdown mode (near the bottom of the Application tab) from "when startup form closes" to "when last form closes".

    BB

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Close one form and open another

    [sorry, accidentally posted twice]
    BB

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Close one form and open another

    Also, you MUST Show the new form BEFORE you Close the current form. If you Close the current form first then the last form will have closed at that point and the app will exit.

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