to use a variable, try this:
//try to use descriptive variable.
public bool formIsOpen = false;
if(!formIsOpen)
{
form2.Show();
formIsOpen = !formIsOpen //toggle the flag
}
else
{
MessageBox.Show("窗口已经打开"
;
}
But this code does not really work because the user can close the second form, and your varible isFormOpen is still true....
The best way is still check if (form2 == null)
if (form2!== null){
MessageBox.Show("窗口已经打开"