### Create Menus by Code

Example creating by code menus with menuitems and add these to a menubar created with the B4J Visual Designer.
Menu Structure:
File
Open
Close
Options
OptionA
Help
About
Define the MenuItems as globals
`Sub Process_Globals
' Menus
Private MenuBar_Main As MenuBar
Private File_Open As MenuItem
Private File_Close As MenuItem
Private Options_ViewThemes As CheckMenuItem
Private Help_About As MenuItem
...
Init the Menu_Init routine to create the menus, menuitems
`Sub AppStart (Form1 As Form, Args() As String)
...
Menu_Init
...
End Sub`
Init the Menus
`Sub Menu_Init
Dim Menu_Files As Menu
Menu_Files.Initialize("File", "")
MenuBar_Main.Menus.Add(Menu_Files)
File_Open.Initialize("_Open", "File_Open")
Menu_Files.MenuItems.Add(File_Open)
File_Close.Initialize("_Close", "File_Close")
Menu_Files.MenuItems.Add(File_Close)
Dim Menu_Options As Menu
Menu_Options.Initialize("Options", "")
MenuBar_Main.Menus.Add(Menu_Options)
Options_OptionA.Initialize("OptionA", "Options_OptionA")
Options_OptionA.Selected = True
Menu_Options.MenuItems.Add(Options_OptionA)
Dim Menu_Help As Menu
Menu_Help.Initialize("Help", "")
MenuBar_Main.Menus.Add(Menu_Help)
Help_About.Initialize("_About", "Help_About")
Menu_Help.MenuItems.Add(Help_About)
End Sub`
Menu Actions
`Sub File_Open_Action
Log("File_Open")
End Sub`
`Sub File_Close_Action
Log("File_Close")
End Sub`
`Sub Options_OptionA_Action
Log("Options_OptionA")
End Sub`
`Sub Help_About_Action
Log("Help About")
End Sub`
`

Changed: 2018-05-06 17:45, Category: Menu, File: T6C220M2171.htm, ID: 2171