Click to See Complete Forum and Search --> : Dynamic Menu Creation


August 16th, 1999, 11:21 AM
How do we append a submenu item to a menu item dynamically. i.e. The way the recently used files are appended. I want to show this submenu which is created dynamically as a popup menu, I shall do this by hiding the main menu item. Is this possible. Please help.

Ganesh Bala
August 16th, 1999, 03:03 PM
Generally to create dynamic objects you need to start with a array of 1 item at design time with index 0.
At run time from your code you can load more items of the array by saying

Load control(i)
'set properties appropriate for the control
'make it visible, by default not visible
'always keep index 0 not visible.

you can use collection feature on the control array at any time to get the count and process the items in the array.

Jan Businger
August 17th, 1999, 06:02 AM
Hi,
You can dynamically add any type of intrinsic VB control, EXCEPT menu items. Unfortunately, this limitation prevents developers from devising customable menu structures with top-level menus and submenus built on the fly

Sorry

Jan

Chris Eastwood
August 17th, 1999, 06:11 AM
You CAN add menu items dynamically on the fly - as long as their not menus such as :

Menu1
Menu2->Menu3 *

(the menu3 style).


It is possible to add menus by using the 'Load' command, eg:

Place a menu on your form called 'mnuFile', caption 'File'. Add a menu beneath this called 'mnuFileItem' with an index of '0'.

In your form load do :-


Dim lCount as Long

for lCount = 1 to 5
Load mnuFileItem(lCount)
mnuFileItem(lCount).Visible = true
mnuFileItem(lCount).Caption = "Item " & lcount
next




You could then show this menu as a pop-up whenever the user clicks somewhere on the form, eg:


private Sub Form_MouseUp(Button as Integer, Shift as Integer, X as Single, Y as Single)
If Button = vbRightButton then
PopupMenu mnuFile
End If

End Sub






Steve at http://www.vbaccelerator.com has an excellent Free API menu control (with source-code) that is very easy to use. This allows you to build SubMenu items on the fly (with icons and plenty of fancy highlighting options too!)



Chris Eastwood

CodeGuru - the website for developers
http://www.codeguru.com/vb