Here is the issue:
I have a multi-form application developed on C# with two forms, after I press a button I hide the first form and show the second, but how can I show the first form again if I close the second one pressing the red close button on the upper right of my window?
The FormClosing event doesn´t get this action...
Plz help me and Thanx for any answer
Disable the X close option for form 2 and instead put a button within the form that will perform the tasks of re-showing the first form and closing the 2nd.
Alternately, the FormClosing event SHOULD catch the close of the form and allow you to use the event handler to re-display the prior form with the possible exception being if the form you are closing is a modal dialog box as this is not disposed when the close is clicked but rather rendered hidden.
While I'm sure you've read it already this page has some resource information on the use of the formclosing event that may or may not help.
Ok I made it!!! Thanx for the help guys
I ended up using the FormClosed event.
Modified the constructor on the second form to recive the first form and then showed the first within the FormClosed event.
Just as an aside...if you have created and shown the second form within the first, you can add an event handler within the first form to catch the closing of the second form. (is that as confusing as it seems to me? lol)
public partial class frmLogin : Form
//create instance of form to show when user logs in
private frmMainMenu mainMenu = new frmMainMenu();
//bind handler to form closed event so login form can react to main menu being closed
mainMenu.FormClosed += new FormClosedEventHandler(mainMenu_FormClosed);
//when main menu is closed, unhide login form
void mainMenu_FormClosed(object sender, FormClosedEventArgs e)
this.Visible = true;
//button to test login process
private void button1_Click(object sender, EventArgs e)
//hide login form
this.Visible = false;
//reset main form - clear any changes made previously and reinstantiate if disposed
mainMenu = new frmMainMenu();
//show main menu
(Yeah It is kind of confusing lol.)
But I used the form closing event on the second form and passed the first form instance to the second form constructor hehe,
BTW tnx cause I didn't realize i had to reset the second form when i close it.