Hi!
I am a novice.I
have 2 Forms form1 and form2. On form1 i have placed a 2 buttons.
Button1 takes the user to form2 using form2.show(); method and Button2
makes to user to exit from application which has a code of
this.close(). It works fine and when user clicks that button2, it
exits from the application and stops debugging fine.
Problem
lies when user go to Form2 (which has a go back button that takes user
back to form1) and comes back to Form1 to exit from application. now
after coming back to Form1 and pressing the exit button, Form1 gets
closed Ok but project wont return from debugging mode so i have stop
debugging manually every time.
Though I am Disposing the Form2
object to release all the resouces before coming back to Form1 but
still doesnt helps. Any thoughts?
here is the code on the Form2.
private void lable_back_MouseClick(object sender, MouseEventArgs e)
{
Form1 frm = new Form1();
frm.Region = this.Region;
this.Close();
this.Dispose();
frm.Show();
}
Any help would be appiciated.
Loading
AnujaPosted Dec 18, 2007, 7:57 AM
AlanPosted Dec 15, 2007, 8:46 AM
The problem is this line:
Form1 frm = new Form1();
which is creating a new instance of Form1 rather than giving you a reference to the existing instance. If you have .NET 2.0 or later, then replacing it by this line should fix the problem:
Form1 frm = (Form1)Application.OpenForms["Form1"];