Jump to content

How do you create new forms and link them?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Tezelia

Tezelia

    Newbie

  • Members
  • PipPip
  • 14 posts
Ok for my game I would like to create a menu form which has a button called 'start game' which then links to the game form.

1) How do I create a new form hence a main menu for my game?

2) How do I link that form to another form?????

For instance if form1 is my gaming code and I create a new form called 'main menu' and add a button, how do I say after clicking start game on mainmenu form, it starts the game

Please need urgent help ):

Thanks

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
You would need some way to reference the main form (game form) from the code in the menu form, so what I would do is alter the constructor for the menu form and create a parameter to pass in a form, which would be the main game form. When you declare your new menu form from the game code, pass in the game form as that parameter. Have your menu form store the game form in a class variable, and whenever you want to link back to the game code, just use that variable to call any of the public methods in your game form.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Tezelia

Tezelia

    Newbie

  • Members
  • PipPip
  • 14 posts
Thank you

But basically

When I select my project, create a new form called 'menu', make a button called start game, double click that button and type in the code

form1.show() 'form1 is the game form

The menu form doesn't pop up and show 'start game', it just goes straight into the game.... ):

Why is this happening?

Thanks

#4
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
When you create a new project, the first form created is the one that launches by default. You can change this, or you can create a new project and create the menu form as the first form, then add a new form for the game form.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#5
Tezelia

Tezelia

    Newbie

  • Members
  • PipPip
  • 14 posts
wow, I think you have identified my problem

How can I change the default form and make the new form my default form so I can link the new default form with the game or current one???

On the project window thingy on the right hand side my form has this arrow sign which I think is stopping me from linking forms because whenever I add a new form, add the code behind a button 'start' and run it, nothing happens and instead of mainmenu form appearing the game just starts....

Nonetheless how do I change my default form, please, please, please

Thank you!!!!!!!! You have definetly identified my problem

My CW is due in Monday and I g2g present it, this is my 1st year

KIND REGARDS

#6
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
This link should tell you how to do this:
How to: Change the Startup Object for an Application (Visual Basic)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users