Determining if WindowsForm is open and closing it
-
I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help
-
I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help
hi, if you only have one form you can make the form global to access it by click on menu item.. if you have more than one form on the panel2 you need to interate through the ControlsCollection of Panel2 to determinate if one of the controls is a Form or not. greetz :)
-
hi, if you only have one form you can make the form global to access it by click on menu item.. if you have more than one form on the panel2 you need to interate through the ControlsCollection of Panel2 to determinate if one of the controls is a Form or not. greetz :)
Thank you for your respond It will always be one form, but I need the form name or id to close it and I dont want to hardcode the forms name. I want basically: Is there a form open, if there is retrieve its id and then say id.close
-
I have a splitcontainer on my form. Panel1 has my menu and panel2 holds the WindowForms. If I click on my menu in panel 1 it should check if a form is loaded in panel2.If there is a form, then it closes it. Thanks for everyones help
What I would do is in your main form I would create a form lavel variable that returns a form i.e
Private OpenForm as Form
. I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do thisIf Not OpenForm Is Nothing Then
'Do Work Here
Else
OpenForm.Close
End IfHope this helps Happy Coding
-
What I would do is in your main form I would create a form lavel variable that returns a form i.e
Private OpenForm as Form
. I would assign this to the current form that is opened in the procedure that opens the form, and in the procedure that checks if a form is open you can just do thisIf Not OpenForm Is Nothing Then
'Do Work Here
Else
OpenForm.Close
End IfHope this helps Happy Coding
Brilliant, thank you it's working just the way I wanted it to work.
-
Brilliant, thank you it's working just the way I wanted it to work.
Pleasure, glad it helped. Just be sure to make sure you set the OpenForm variable to nothing when the form is closed, else this will not work the second time. :-D Happy Coding