Add Menu Sub-items at Runtime, No API Calls Needed

By | 2024-07-21

This simple program adds menu items or subitems at runtime without any api calls.

Put a label on the form, in the menu editor add a menu item call it FileMenu with an index of 0, then add a subitem call it FileMenu1 with an index of 0

To add new menus add them as FileMenu(**)
To add subitems add them as FileMenu1(**)

Change the names to suit

Private Sub FileMenu1_Click(Index As Integer)
Select Case Index
Case Index
Label1.Caption = Index
End Select
End Sub

Private Sub Form_Load()
Dim x As Integer
For x = 1 To 4
    Load FileMenu1(x)
    FileMenu1(x).Caption = "Menu " & x + 1
    FileMenu1(x).Visible = True
Next x
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.