by clicking a button at form2 i went to form3 but again from form3 i wnt 2 go 2 frm2by clicking a button in frm3
how to go to previous form
Collapse
X
-
Tags: None
-
I am not sure whether there is any inbuilt mechanism to get the previous form, If it is there then i dont know
but it there is none then you can do following.
1. Create a Form Type variable. Name it Current Form
2. Whenver u create a new instance, you store CurrentForm instance to PreviousForm Insance and new insance inthe CurrentForm Reference.
3. Whenever you want to open previous form you access PreviousForm.Sh ow() to show it.
4. Create the funcationality using above logic.
Best of luck... -
What fastestindian suggested is spot on; however, an alternative for a cleaner interface is to use UserControls to populate a panel instead of separate forms.
For example...
Now you can create a bunch of WizardPanel objects and design them using designer to look like however you want.Code:public class WizardPanel : UserControl { ... }
Code:public class MyPanel1 : WizardPanel { ... } public class MyPanel2 : WizardPanel { ... } public class MyPanel3 : WizardPanel { ... }Create a Wizard object as a private member in your main form. Also throw two panels onto your form. Dock one to fill and the other to the bottom. Put a next/back button in the lower button.Code:public class Wizard { private List<WizardPanel> m_panelList = new List<WizardPanel>(); private int m_currentIndex = 0; public void Add(WizardPanel panelToAdd) { ... } public void Remove(WizardPanel panelToRemove { ... } public void Remove(int index) { ... } public WizardPanel Get(int index) { ... } public WizardPanel GetFirst() { ... } public WizardPanel GetNext() { ... } public WizardPanel GetLast() { ... } public WizardPanel GetPrev() { ... } }
In your constructor, you can put...
Your next button's click event ...Code:myWizard.Add(new MyPanel1()); myWizard.Add(new MyPanel2()); myWizard.Add(new MyPanel3()); mainPanel.Controls.Clear(); mainPanel.Controls.Add(myWizard.GetFirst());
... and the back button ...Code:mainPanel.Controls.Clear(); mainPanel.Controls.Add(myWizard.GetNext());
This is just a stubbed out, bare bones version of a way to get the functionality you want inside a single form instead of instantiating new ones. It may not be what you need (as I said, I think fastestindian's answer is the best solution for what you described) but it's always fun to think about other ways to go about it :)Code:mainPanel.Controls.Clear(); mainPanel.Controls.Add(myWizard.GetPrev());
Good luck!Comment
Comment