This answer is based on the assumption that this is a WinForms Project, that Form1 is the "Main Form," started automatically when the Project is compiled and run, and that "button13" is in Form1 !
All the code examples shown here are meant to be inside Form1.
1. Why would you recreate Form2 every time Button13 is pressed ?
I suggest you create Form2 once, in the Form1_Load Event Handler, for example:
private Form2 f2;
private void Form1_Load(object sender, EventArgs e
f2 = new Form2();
f2.Closing += new CancelEventHandler(f2_Closing);
2. Then, in the Closing EventHandler for Form2, I would not close Form2 !
: I'd use this:
private void f2_Closing(object sender, CancelEventArgs e)
button13.Enabled = true;
e.Cancel = true;
3. So, then, Form1's button13 Click EventHandler would look like this:
private void button13_Click(object sender, EventArgs e)
button13.Enabled = false;
Discussion: unless there's a very good reason you want to use a fresh/new version of Form2 every time you click button13 ... and there could be one ... I'd suggest this approach.
If we assume that Form1 is the "Main Form" which is launched in the Program.cs file, then closing Form1 ... even if Form2 is open ... will automatically close Form2. In other words: you do not have to worry about "dis-connecting" Form2's Closing Event Handler.
... edit #1 ...
If you are ever in a situation where Form1 is not
the main form used as the argument to 'Run' in the Program.cs file, and you wish to guarantee that Form2 will be closed if Form1 is closed, you can add this code to Form1:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
if (f2 != null) f2.Dispose();
}... end edit #1 ...