Menu - Open only 1 form.

  • Thread starter Thread starter Vince
  • Start date Start date
V

Vince

I'm creating a dynamic menu. I've extended the menuitem
class to have a "form name" property. This property is
the name of the form that I will open when the menuitem
is selected.

Here's my code to open up the form:
Dim menuItem As MyMenuItem.MyMenuItem = DirectCast
(sender, MyMenuItem.MyMenuItem)
Dim myFormName As String = menuItem.itemName
Dim frm As Form = Activator.CreateInstance
(Type.GetType(myFormName))
frm.Show()

The only problem I have with this is that it's creating
multiple forms if I choose the menuitem multiple times.
If the form is already loaded, I want to bring that form
into focus, not open a totally new form.

Any ideas how to do this? (this is not a MDI forms)
 
hey Vince,
here's a suggestion, albeit a bit of a hack:

try using an arraylist called OpenForms, stored as a private variable inside
the form containing the menu. every time you create a form, add it to the
arraylist, and when you want to know whether one is open or not, check the
types of all the forms in the arraylist and see if there is a match. i
haven't tried it but i think it should work. you won't suffer additional
memory overhead because the forms will be stored by reference in the
arraylist, not duplicated by value.

hope this helps
tim
 
Back
Top