Need help managing multiple forms
Hey everyone,
I am a beginner programmer, and taking my first course in VB.NET in college.
I am writing a program that teaches the user step by step to solve a rubiks cube.
One problem I am having is how to manage the 20 forms that make up my program.
Currently, when the user procedes to the next step, I make the current form invisible, and show the next form.
ex. Nextbutton click
form2.show()
me.visible = false
This causes two problems. When the user closes the application, the program still is "running", and you have to go to a task manager and end the .exe process.
I have tried doing
form2.show()
me.close()
but that closes the entire program instead of just showing the next step.
I had no idea how to word this problem, so if it has already been answered, will you please direct me to the other thread?
Thanks!
Weston
Re: Need help managing multiple forms
What you need is a wizard type application. You're familiar with such types of applications (nearly all installation programs have Next, Previous buttons so the user can go back if he desires or proceed to the next step). This design is perfect for the app you create.
Basically it's a single form that has a number of containers (panel, for example) each of them represents a single 'step' of the wizard. When user clicks the Next button one panel is hidden and another one is displayed (do not be afraid to modify the appearance of your forms from the code rather than in the designer window).
As for the mistake you're doing in your current design - you're using the default instances of your forms. I wish Microsoft didn't allow that in the first place.
You can show a form like this (wrong way):
In this case you allow something within the vb compiler to instantiate your form for you (form2 is a class, not an instance).
The correct way is doing this explicitly. In this case you will control every aspect of your form's behaviour:
Code:
Dim frm2 As New Form2
frm2.Show
But I still think you're ought to redesign your app into a wizard.
Re: Need help managing multiple forms
If you've already got 20 forms and don't want to redesign, use your second code (with the Me.Close()) and set the project's shutdown mode to "When the last form closes". (Double-click on "My Project" in your solution, and find the drop-down.)
Re: Need help managing multiple forms
Thank you so much for the advice. This will fix a lot of headaches I have been having in runtime.
I see you are from Russia, so
Болшое спасибо!
Re: Need help managing multiple forms
I decided to just go ahead with what I originally thought as the quickest solution of changing every
Code:
Formx.show
me.visible = false
with
Code:
dim frmx as new formx
frmx.show
me.close
It has created another issue with the rest of my program, I am assuming because it is a "new" form.
In form3 I have a Friend string variable, that was used in just about every other form such as
Code:
How many stickers are on the & Form3.topface & face?
Since making the change to every form as a new form, the variable no longer is stored and doesn't appear on any of the other forms after making the change.
Again, I am a beginning programmer, so if anyone could let me know 1) why this is truly happening, and 2) the easiest way to fix it.
Thanks
Re: Need help managing multiple forms
Quote:
Originally Posted by
westong5
In form3 I have a Friend string variable, that was used in just about every other form
Get it out of Form3 and put it in a module, so it's accessible anywhere in your project.
Re: Need help managing multiple forms
Works perfectly.
thanks a lot