Form2 currentActiveForm2 = null; void yourButton_Click(object sender, EventArgs e) { if (currentActiveForm2 != null) { currentActiveForm2.Close(); // if currentActiveForm2 is null, your button has not been clicked yet, so the form doesn't exist yet and we cannot close it. } currentActiveForm2 = new Form2(); currentActiveForm2.Show(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)