I want to create a DropDownMenu in a DesktopToolbar at runtime. This is my code:
QuitButton = New DesktopToolbarButton
QuitButton.Name = "QuitButton"
QuitButton.Caption = "Quit"
QuitButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.PushButton
QuitButton.Icon = xcirclered
MainWindow(w).MainToolbar1.AddButton(QuitButton)
SpaceButton = New DesktopToolbarButton
SpaceButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.Space
MainWindow(w).MainToolbar1.AddButton(SpaceButton)
FilesButton = New DesktopToolbarButton
FilesButton.Name = "FilesItems"
FilesButton.Caption = "Files"
FilesButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.DropDownMenu
FilesButton.Icon = folder_open
MainWindow(w).MainToolbar1.AddButton(FilesButton)
//SubMenu General Files
Var subMenu As New DesktopMenuItem
subMenu.Text = "General"
subMenu.AddMenu(New DesktopMenuItem("Countries"))
subMenu.AddMenu(New DesktopMenuItem("Languages"))
MainWindow(w).MainToolbar1.FilesItems.AddMenu(subMenu)
w a reference to a dynamically created window based on MainWindow. All instructions before the comment line âSubmenu General filesâ work well. However, I am unable to link a dropdown submenu to an element in the menu. The last line in the code is judged as erroneous ('MainToolbar has no member named FilesItems").In one of the statements above, I created a DesktopToolbarButton (style DropDownMenu) with the name âFilesItemsâ. Any idea what I am doing wrong?
Why are you creating buttons instead of DesktopMenuItems?
I want to have two buttons in the DesktopToolbar: âQuitâ (this is a pushbutton) and âFilesâ (this is a dropdownbutton. Under âFilesâ I want to have a menu âGeneralâ and under âGeneralâ two further items âCountriesâ and âLanguagesâ. âQuitâ and âFilesâ are displayed when I remove the last line of code. However, I have problems to add the submenu under the âFilesâ dropdownbutton.
The name of the object is a string property of the object.
You need the reference of the object.
Your supposed âFilesItemsâ object is really the object FilesButton.
@Carlos_De_Backer Something like this
//SubMenu for FilesButton
Var subMenu As New DesktopMenuItem
subMenu.Text = "General"
subMenu.AddMenu(New DesktopMenuItem("Countries"))
subMenu.AddMenu(New DesktopMenuItem("Languages"))
// Button
FilesButton = New DesktopToolbarButton
FilesButton.Name = "FilesItems"
FilesButton.Caption = "Files"
FilesButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.DropDownMenu
FilesButton.Icon = folder_open
FilesButton.AddMenu(subMenu)
MainWindow(w).MainToolbar1.AddButton(FilesButton)
Thank you so much. We are close to find a solution. The statement FileButton.AddMenu(subMenu) is not valid for a DesktopToolBarButton and must be changed to:
FilesButton.Menu = subMenu
I try to find why the text âGeneralâ is not displayed (only the items âCountriesâ and âLanguagesâ are shown now). I tried to have âCountriesâ and âLanguagesâ as a submenu of the item âGeneralâ.
Finally, I solved the problem with the expert help of Rick Araujo. This is the piece of code:
Var subMenu As New DesktopMenuItem
Var subMenu1 As New DesktopMenuItem
subMenu1.Text = "General"
subMenu1.AddMenu(New DesktopMenuItem("Countries"))
subMenu1.AddMenu(New DesktopMenuItem("Languages"))
subMenu.AddMenu(subMenu1)
Var subMenu2 As New DesktopMenuItem
subMenu2.Text = "Settings"
subMenu2.AddMenu(New DesktopMenuItem("Login codes"))
subMenu.AddMenu(subMenu2)
FilesButton = New DesktopToolbarButton
FilesButton.Name = "FilesItems"
FilesButton.Caption = "Files"
FilesButton.ButtonStyle = DesktopToolbarButton.ButtonStyles.DropDownMenu
FilesButton.Icon = folder_open
FilesButton.Menu = subMenu
MainWindow(w).MainToolbar1.AddButton(FilesButton)
1 Like