adding menu items at run time 
Author Message
 adding menu items at run time

Thanks for you suggestion. Code works except for one
problem. I need to add the menu items at run time when the
Parent menu item is clicked (in your example, instead of
using the command button, the user would click the "File"
menu, and the sub items would be added).  Specifically,
I'm adding the names of all open Excel workbooks as sub
items (similar to a Window List) to the "Window" menu item.

Do you know of a workaround for this - or am I just
missing something.

Thanks
Bill

*************************

Here is a sample to dynamically add and remove menu items:

1.  Create a new Standard EXE project.
2.  Create a menu on Form1.  The menu will look like the
following...
         File
              Item 0
3.  Set the name property of "Item 0" to mnuItem
4.  Set the Index property of "Item 0" to 0.
5.  Add two command buttons to Form1.
6.  Paste the following code into Form1's code window:

 Option Explicit
Private Sub Command1_Click()

  Dim x As Long

  For x = 1 To 10
     Load mnuItem(x)
     mnuItem(x).Caption = "Item" & x
     mnuItem(x).Visible = True
  Next x

End Sub

Private Sub Command2_Click()

  Dim x As Long

  For x = 10 To 1 Step -2

     Unload mnuItem(x)

  Next x

End Sub
Private Sub mnuItem_Click(Index As Integer)

  MsgBox "You clicked menu item: " & mnuItem(Index).Caption

End Sub

7.  Save and run the sample.
8.  Click the first command button.
RESULT: The menu should have 10 items added to it.
9.  Click the second command button.
RESULT: Several menu items are removed from the menu.
10.  Click any item from the menu.
RESULT:  You should receive a message box indicating which
item you clicked.

Best Regards,

Alick Ye



Mon, 02 May 2005 22:55:41 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Adding menu items at run-time

2. Code to add menu items at run time.

3. Adding Menu item at run-time

4. Adding menu items at run-time?

5. Adding menu items at run-time

6. How to add menu items at run time?

7. Adding menu items at run time

8. Adding menu items at run time

9. Adding elements to a control array of Menu items with subMenus at Run time

10. How to add menu items at run time in Visual Basic 5.0 ??

11. add item menu in control menu when app is run

12. Adding Menu item to the Mail item menu from an outlook Addin

 

 
Powered by phpBB® Forum Software