Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,
I need an advice,i have a smartdevice application,and i have to go from one form to another.For example,i have two forms Form1 and Form2,when i open Form2,Form1 should close. I use this code:
C#
Form2 myNewForm = new Form2();
            
            myNewForm.Visible = true;

            myNewForm.ShowDialog();
        
            this.Close();

but when i close the application,with Application.Exit() i can see the cascade of Forms closing.

Any Help how to do this?
Thanx in advance
Posted
Updated 10-Apr-12 0:46am
v2
Comments
StM0n 10-Apr-12 6:54am    
is "this" the form started by main?

C#
Form2 myNewForm = new Form2();
            
            myNewForm.Visible = true;
 
            myNewForm.ShowDialog();
        
            form1.hide();
 
Share this answer
 
Comments
IviKAZAZI 10-Apr-12 6:20am    
Does the hide() close the form???
StM0n 10-Apr-12 6:52am    
No...
From the code given in the question it appears that the myNewForm is declared in the current form. Hence, eventhough this.Close(); is called the GC will not release the memory held by the present form referred by this, as a reference to myNewForm is held by this form.
So, declare myNewForm in another location accessible from this form.
myNewForm.Visible = true; is redundant as myNewForm.ShowDialog(); makes it visible.
It is better to call Dispose method from outside the form, like Fom1.Dispose() for immediate disposal by GC.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900