Kim Larsen

Kim Larsen

  • NA
  • 3
  • 0

Open/Close form on same button

Aug 13 2009 5:11 AM
Hey all! I have a problem, which consist of a button that is supposed to open a form, and if i click that button again, the Form should close, and only 1 of this form should be able to run at the time. Problem is that it keeps opening more forms as i click my button. [code] private void button1_Click(object sender, EventArgs e) { int on = 1; int off = 0; StartMenu StartMenu = new StartMenu(); if (on < off) { StartMenu.Dispose(); on = 1; off = 0; } else if(on > off) { StartMenu.Show(); off = 1; on = 0; } } [\code] This is the code that i attempted to make for the button to register whether the button is active or inactive, and choose if the Form should open or close. :) Hope you can help!! Looking into it my code was not readable, i'll try to organize it. :)

Answers (3)