There is two Forms in my project : Form1 and Form2. There is a button in Form1, and what I want to do is closing Form1 and showing Form2 when that button clicked.
Fi
Write that into your method which is executed while FormClosing
event occure.
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Display a MsgBox asking the user if he is sure to close
if(MessageBox.Show("Are you sure you want to close?", "My Application", MessageBoxButtons.YesNo)
== DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = false;
// e.Cancel = true would close the window
}
}