JadeWolf324 Posted July 23, 2004 Share Posted July 23, 2004 im trying to make a simple wizard in VB.NET. it has 2 forms, and i want the user to be able to press the back button and makes changes to the information on form 1, if they hit the back button which is found on form 2. in other words, i want only these to forms made and have all the info kept on them...in VB6 all i had to do was me.hide frm2.show thats not the case now...can someone help? Link to comment Share on other sites More sharing options...
0 Winston Posted July 23, 2004 Share Posted July 23, 2004 You have to instantiate a new instance of the form Dim frm2 as New Form2() frm.Show() Link to comment Share on other sites More sharing options...
0 John Veteran Posted July 23, 2004 Veteran Share Posted July 23, 2004 Learn some basic object oriented concepts, you'll do a LOT better in .NET ;) Link to comment Share on other sites More sharing options...
0 James Rose Posted July 23, 2004 Share Posted July 23, 2004 not to change your approach but... Wizards tend to not use multiple forms. Instead use on form and use a placeholder array for each "page", then it's easy to go back and forward in your wizard. Link to comment Share on other sites More sharing options...
0 JadeWolf324 Posted July 23, 2004 Author Share Posted July 23, 2004 i see, but the size of the window changes on each form..is the only problem there. and as for the You have to instantiate a new instance of the formDim frm2 as New Form2() frm.Show() wouldnt that make a new one? i want it to have the info stay if the user wants to go back and forth from the wizard. Link to comment Share on other sites More sharing options...
0 John Veteran Posted July 23, 2004 Veteran Share Posted July 23, 2004 What you're basically saying with that code is "make a new object i can use, and build it like a Form2 item" (Y) Classes (including forms) aren't meant to be designed as a single instance. You're still thinking like you're using VB6, saying "here's what the form looks like, now create it". It's just not done that way in OOP (object oriented programming) :no: Link to comment Share on other sites More sharing options...
0 Winston Posted July 24, 2004 Share Posted July 24, 2004 What you're basically saying with that code is "make a new object i can use, and build it like a Form2 item" (Y) Classes (including forms) aren't meant to be designed as a single instance. You're still thinking like you're using VB6, saying "here's what the form looks like, now create it". It's just not done that way in OOP (object oriented programming) :no: Yes it will make a new one... so that's why you could create a Public Object Variable and instantiate the that class (form in this case), and just work off it... I had a friend who taught me some other way to do like wizards, if you wanted it to be easy, you can just have one form, and just layout each wizard screen on the whole form, top to bottom, and when the user clicks the next button, the items will shift up and change accordingly, that's a much better idea, than having alot of forms, just to create a wizard. Link to comment Share on other sites More sharing options...
0 DrZoidberg Posted July 24, 2004 Share Posted July 24, 2004 I agree with the "one form" approach. It's a lot easier to keep track of the values on each "page" of the wizard. Stick each page of the wizard on a panel and hide and show each panel as the user clicks on the "Next" and "Previous" buttons. I've written a wizard user control that makes it even easier: it takes care of all the pages on the wizard, the Cancel/Finish/Next/Previous buttons and so on. All the programmer needs to do is to set the correct number of pages in the VS.Net designer and add the appropriate controls to each page. The "multiple form" approach seems a bit overly-complicated IMHO. If you really want to continue this way (especially as you say your forms are different sizes, which IME isn't really what happens with wizards - each part of the wizard is the same size), you could create global variables (ugh!) of an instance of each form just before you show the wizard and use the Next/Previous buttons to show these global forms. However, this approach is an awful hack and I feel dirty even suggesting it :). Something like (I'm a C# programmer, so excuse any mistakes): Dim wizardPage1 As New Form1() Dim wizardPage2 As New Form2() Then, when you want to show the first page of the wizard: wizardPage1.Show() In the first form's Next button click event: Me.Hide wizardPage2.Show() In the second form's Previous button click event: Me.Hide wizardPage1.Show() I think that might work, but (a) I'm not 100% sure and (b) it's a dreadful approach. Much better to use a single form and panels or a similar approach. There are probably user controls out there to help you, or you could write your own. Link to comment Share on other sites More sharing options...
0 Cool4 Posted July 24, 2004 Share Posted July 24, 2004 I agree with the "one form" approach. It's a lot easier to keep track of the values on each "page" of the wizard. Stick each page of the wizard on a panel and hide and show each panel as the user clicks on the "Next" and "Previous" buttons. I've written a wizard user control that makes it even easier: it takes care of all the pages on the wizard, the Cancel/Finish/Next/Previous buttons and so on. All the programmer needs to do is to set the correct number of pages in the VS.Net designer and add the appropriate controls to each page.The "multiple form" approach seems a bit overly-complicated IMHO. If you really want to continue this way (especially as you say your forms are different sizes, which IME isn't really what happens with wizards - each part of the wizard is the same size), you could create global variables (ugh!) of an instance of each form just before you show the wizard and use the Next/Previous buttons to show these global forms. However, this approach is an awful hack and I feel dirty even suggesting it :). Something like (I'm a C# programmer, so excuse any mistakes): Dim wizardPage1 As New Form1() Dim wizardPage2 As New Form2() Then, when you want to show the first page of the wizard: wizardPage1.Show() In the first form's Next button click event: Me.Hide wizardPage2.Show() In the second form's Previous button click event: Me.Hide wizardPage1.Show() I think that might work, but (a) I'm not 100% sure and (b) it's a dreadful approach. Much better to use a single form and panels or a similar approach. There are probably user controls out there to help you, or you could write your own. imagine that you have 2 forms, and want to change the position of a control in a form from the other form without unloading the first form... how would you do it? i use a module to pass the vars but i think this could be easier Link to comment Share on other sites More sharing options...
Question
JadeWolf324
im trying to make a simple wizard in VB.NET.
it has 2 forms, and i want the user to be able to press the back button
and makes changes to the information on form 1, if they hit the back button
which is found on form 2. in other words, i want only these to forms made
and have all the info kept on them...in VB6 all i had to do was
me.hide
frm2.show
thats not the case now...can someone help?
Link to comment
Share on other sites
8 answers to this question
Recommended Posts