Results 1 to 7 of 7

Thread: [RESOLVED] Parent/Child Form Problem [open and closing them]

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    62

    Resolved [RESOLVED] Parent/Child Form Problem [open and closing them]

    Hi all,
    My project is a game, a Hangman game, i have problems with forms, as follows:
    First I want my project to have a splash screen and i put it as start-up form, then when splash screen finish executing itself, it hides itself
    Code:
    this.hide();
    and load the menu form then if you chose new game in menu form it loads new form "pre-game" i did this form to get from the user some parameters for the game,
    from the pre-game form is a button to start the game and shows the "game" form, but as you can see the parent child relationship is like this:
    Splash screen -> Main Menu -> pre-game -> Game.
    Now my problem is .. I can't close the Menu form when the Game form loads, or even hide it. Is there any way to load a form independent from other
    (i mean not as parent/child relationship), just load a form as a parent itself...
    I'm waiting for a reply.
    Thanks in advance

    Jareck
    Last edited by jareck; Feb 10th, 2011 at 08:14 AM.

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

    Re: Parent/Child Form Problem [open and closing them]

    Here's how I suggest displaying a spalsh screen in C#

    http://www.vbforums.com/showthread.php?t=628109

    The other forms can be displayed from the Main method before the main form, either by calling Application.Run or ShowDialog.
    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
    Member
    Join Date
    Sep 2007
    Posts
    62

    Re: Parent/Child Form Problem [open and closing them]

    ok, im going to take a look for the splash screen... thnx
    but can you give me a simple example how to use application.run
    because i was using ShowDialog but still couldn't close the parent form from the child one...

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

    Re: Parent/Child Form Problem [open and closing them]

    Quote Originally Posted by jareck View Post
    because i was using ShowDialog but still couldn't close the parent form from the child one...
    There is no parent or child form and no form is closing any other. The forms are all opened from the main method and they each close themselves.
    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

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    62

    Re: Parent/Child Form Problem [open and closing them]

    I'm really confused right know ! to make my question more clearly... Let's guess I have form1 and form2, is there any way to show form2 from form1 e.g with a button click and then with another button in form2 to close the form1 ?

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

    Re: Parent/Child Form Problem [open and closing them]

    Yes, but I don't quite understand why you would want to in this case. What's the first form that's being closed and what's the second form that's closing 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

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    62

    Re: Parent/Child Form Problem [open and closing them]

    I want'ed to do that because when the game form was shown I wanted the Menu form to be closed, it just was annoying in that way.
    However thnx a lot for your help, I found the solution here:
    Code:
    public static void ThreadProc()
    {
        Application.Run(new Form());
    }
     
    private void button1_Click(object sender, EventArgs e)
    {
        System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
        t.Start();
    }
    Reference: http://social.msdn.microsoft.com/for...-426521fe60f1/

Tags for this 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