المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Closing a form



C# Programming
04-13-2009, 01:00 PM
I wanted to close a previous form after calling the next form. How do i do that?
I have many form in my application. When i exit the application using the following code all the forms are closed one by one. Instead i want to close the previous form after calling the next form in order to avoid the closing of all the forms after exit. Please help.

DialogResult result = MessageBox.Show("Do you want to exit?", "Exit-Window", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
if (result == DialogResult.OK)
Application.Exit();


I have tried with the following code but the application exits automatically.
The code is written on the command button on Form1. http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif
private void button1_Click(object sender, EventArgs e)
{

Form2 frm2 = new Form2();
frm2.Show();
this.Close();


}

http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif