Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need code for closing particular form in windows application(C#).......
Posted

Try:
C#
myForm.Close();

Where myForm is teh variable holding teh instance of the form you wish to close. I.e. when you cretaed teh form instance, save it in myForm:
C#
FormIWantToClose myForm = new FormIWantToClose();
...
myForm.Show();
...
myForm.Close();
 
Share this answer
 
Comments
RaisKazi 30-Aug-11 3:59am    
My 5!
Try These:

C#
private void button1_Click(object sender, EventArgs e)
        {
            myForm frm = new myForm();
            
            this.Close();
        }


or:


C#
private void button1_Click(object sender, EventArgs e)
        {
             myForm frm = new myForm();
            frm.Close();

        }


hope it helps :)
 
Share this answer
 
Comments
RaisKazi 30-Aug-11 3:59am    
My 5!
Uday P.Singh 30-Aug-11 4:06am    
Thanks :)
If you're searching for a particular form by name you could use
System.Windows.Forms.Application.OpenForms
Find the one that you want and call Close.
 
Share this answer
 

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