Re-Initialization Problem

wangj

Member
Joined
Jul 2, 2008
Messages
5
Programming Experience
Beginner
Hello I'm a beginner in VB.net and a problem came up while I was transferring between Forms:

I'm currently making a program that lets the user practice their times table. Before going into the practice form I popup a form called "Form3" that lets the user select which times table number they want to practise. After they pressed a button I use me.hide and form2.show (Form2 = the question form)
The first transition between the forms works well.
After they’ve answered a series of 12 questions I’ll display their score and then ask them if they want to restart/reload.
After the user pressed yes the following happens (Which is where the trouble came from)

If response = vbYes Then
reload()
Me.Hide()
Form3.Show()
Else
Me.Hide()
Form1.Show()
End If

And the code for reload():

Dim Controls As ControlCollection = Me.Controls
Controls.Clear()
InitializeComponent()
Form2_Load(Me, Nothing)

So basically what I want to do is to refresh form2 and then switch to form3 to let the user choose a new number.
The problem I encountered was that after the user pressed a button in form3 and form2 appears, what form2 shows the user is the state of form2 before the message box appears.

So my question is: Is there a way of “Refreshing” form2 (ReInitialize all the variables)
 
hi wangj

Welcome to the forums.

You could instead of hiding the forms close them.

VB.NET:
dim frmOpenThisOne as new Form1
frmOpenThisOne.Show()
Me.Close

You would have to make sure to set the project properties to close when last form closes, instead of the default.
 
Back
Top