views:

243

answers:

3

Hi

I have Windows mobile program that has 4 Forms,

Form1 -> Form2 ->Form3 -> Form4

If I stay in Form4 and I want to go Back to Form1, How I can Do it ?

thank's

A: 

Show Form1 in Form4 Closed event.

danish
+1  A: 

You can use a FormHandler object (implemented as a Singleton) that will act as a stack of forms. Each time, you create a new form, you push it onto the stack. When you close a form, you pop it off the stack and show the next form from the stack. In your example you would pop all forms until you get to (and show) Form1.

Sebastian
A: 
myForm4.Close();
myForm1.ShowDialog(); // assume myForm1 is a Form1

Note that this is a pretty bogus approach to things if you're making, e.g., a wizard interface. If you're making a wizard interface, you're much better off making each wizard page a UserControl and using the "< Back" and "Next >" buttons to add or remove the Usercontrol pages from the one form. That avoids bad things like the wizard moving around the screen when next and back are pressed of the user has dragged it. It also neatly side-steps the parent window issues that you're creating for yourself by not specifying a parent window in ShowDialog().

Greg D
Downvotes without explanatory comments are rude.
Greg D