Lets say you have a menu already. Is there a way to add menus at runtime. could someone post the code. thanks
Printable View
Lets say you have a menu already. Is there a way to add menus at runtime. could someone post the code. thanks
You have to make all the menu's you think you'll need at design time, then change their visible and caption properties to make it look as if your adding them at run time, start them off as invisible and then make them visible.
Thanks Sam
Not quite true Sam, you can add menus if they are in a Menu Control Array. Except for the top-level entries, any menu item can be in a control array. How do you think, for exmaple, the Windows List works in MDI Forms?
I wasn't sure so I didn't mention them.
Sorry, little mistake, you can also load top-level entries as well, I just did a little test. The only problem is that every top-level entries does not (for obvious reasons) contain the same sub-menus as the first index. Oh yeah, if you were wondering how to do it:
First, when you create your menu items, you must set the index of the menu that you want created multiples of to zero or some arbitary number, just as long as it knows it is in a control array.
Now to add a menu item (we'll call the control array Menu item mnuTest) do the following:
Call this as many times as you want to add items. You may also want to extend this function to allow other properties of the new menu item to be passed, such as Enabled and Checked.Code:Private Sub AddMenuItemTest(sCaption As String)
Dim iNextIndex As Integer
iNextIndex = mnuTest(mnuTest.UBound).Index + 1
Call Load(mnuTest(iNextIndex))
mnuTest(iNextIndex).Caption = sCaption
End Sub
Hope this helps.