Question Forms to be loaded on random

v1rTUAL

New member
Joined
Oct 11, 2011
Messages
3
Programming Experience
Beginner
I am trying to create a simple game for children for my final year project, I have a number of form that will display a different type of question for each form. I am aware of the form1.Show() and form1.Hide(), is there anyway that I can load a form on random. for e.g, lets say I have form1, form2, form3, form4.... I want the order of the forms to be shown in random order. Thank you in advance.
 
Put your forms into a List. Use a Random object to generate a random index for that List. Remove the form at that index and display it. Continue until the List is empty. If you don't mind repeats then use an array instead of a List and don't remove.
 
Thank you very much for the answer, I got it after a few tries, However i have another question. this is the scenario. I have total of 50 forms, starting with the Menu form. For example, when the user complete the game in from1 it will allow them to enter form2. i have added a menu button on each forms so that they could always return to the MENU, my question is, what do i do so that they could return back to the previous form that they came from. I do not want them to start the game from the beginning again. for example if the user return to menu in level 10, they should be able to return back to level 10 when they click on the return to game to game button. Thanks in advance.
 
You could also declare the forms as a control array, and just randomize the array index...

VB.NET:
Dim Forms(50) As Windows.Forms.Form

Then pick a number between 0 and 49 and show the form:

VB.NET:
        Dim rnd As Random = New Random(DateTime.Now.Millisecond)
        Forms(rnd.Next(0, 49)).Show()
 

Latest posts

Back
Top