Reputation: 57
I am doing Windows Forms Application. When the user clicks a button I am hiding the current page and navigating to another page. // in the button click event
Vehicle_Registration ob = new Vehicle_Registration(this);
ob.Show();
this.hide();
But the problem here is, in the Vehicle_registration Page, if the user clicks the Close Button in the Control Box then this page is closing, but the previous page(Main Page) is not in visible. I don't want to disable the Close Button. Where i Can write the code for visiability for the Main Page?
Upvotes: 0
Views: 188
Reputation: 22849
Here it would help you a lot to abstract the notion of a Wizard into its own class. It would handle the show/hide of the different forms.
When you instantiate you would have to tell it the sequence of forms you will open. Every form that is subject to handling by the WizardManager should implement an interface that allows the Manager to know when the user presses next. You may also consider inheriting from a base form such that you can put common visual behaviour in one place.
public class WizardManager {
public WizardManager AddStep<T>() where T : IWizardStep, new() {
/* Add code */
return this;
}
public void Start() {
/* Show the first step */
}
}
And you use it like
var mgr = new WizardManager();
mgr.Add<FirstStep>().Add<SecondStep>();
mgr.Start();
Here I am assuming that your forms have default constructor. Now you can place the show/hide code in the Manager and also the code that Alex provided to you. This is one of a number of ways to avoid code duplication as the show/hide/close handling is always the same.
Upvotes: 0
Reputation: 43321
Vehicle_Registration ob = new Vehicle_Registration(this); ob.FormClosed += ob_FormClosed; ob.Show(); this.hide(); void ob_FormClosed(Object sender, FormClosedEventArgs e) { // show current window here }
Upvotes: 1
Reputation: 44605
if I get it right the way you are doing things, you pass this
to the other form constructor so you have a reference to your first Form
in there.
in the Form_Closing event of the second form just do Parent.Show();
or anything similar using the form reference you got in the construction.
Upvotes: 1