Example Popup Menu help please
Posted
#1
(In Topic #1267)
Trainee
I have looked and not been able to find any examples that show me how to use the menu's, the help file is good, but I do need code to see it all in action.
Would somebody have time to write up an example of making a dynamic created popup menu that activated at the mouse position (I can limit it's off screen stuff etc after), but I just want to be able to right click the form (for the example) and have it show a menu containing "Item 1", "Item 2", "Separator", "Item 3" and how I capture the event when I pick them.
I did figure out how to do this in vb6 and Xojo, but gambas doesn't have much example code to learn from, that I've found and the help doesn't seem to work on my Linux Mint either, so maybe that's where all the info is I need.
Thanks for any help, this is the last thing I need to add to my launcher, but I've not even got my code to run whenever I try to create a dynamic menu (or even a fixed one), I just don't understand how to do it.
Happy to share my app/code once I am happy with it, it does have some cool ideas I figured out over the years to handle data and dynamic columns.
Posted
Trainee
I just had to set the Text of the menu items and up it popped.
I'll see how I go detecting the actions, but I don't see it being a problem now.
Posted
Trainee
Code
Dim ContMenu As Menu
Dim MenuItem1 As Menu
Dim MenuItem2 As Menu
Dim MenuItem3 As Menu
Dim Result As - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dim HitItem As String
ContMenu = New Menu(LastOSLinuxStoreMain, False)
MenuItem1 = New Menu(ContMenu, False)
MenuItem1.Text = "Test 1 Menu"
MenuItem2 = New Menu(ContMenu, False)
MenuItem2.Text = "Test 2 Menu"
MenuItem3 = New Menu(ContMenu, False)
MenuItem3.Text = "Test 3 Menu"
Result = ContMenu.Popup(Mouse.ScreenX, Mouse.ScreenY)
HitItem = ContMenu. - - - - - - - - - - - - - - - - - - - - - - - - - -
Message(HitItem)My bad, I still can't figure out how to catch the clicked items, anyone? I assume I either have to capture it as a type set at the top in the - - - - - - - line or check a result at the bottom with - - - - - changed to something, or maybe I am way off?
Posted
Guru

Code (gambas)
- $hPopup.Children.Clear ' clear main popup menu parent items
- ' i just make some menus here. i guess for your needs the creation would be more dynamic/varied.
- hMenu.Name="M1"
- hMenu.Text = "Item 1" ' make text
- hMenu.Name="M2"
- hMenu.Text = "Item 2" ' make text
- ' do not enter any text so it becomes a spacer
- hMenu.Name="M3"
- hMenu.Text = "Item 3" ' make text
- $hPopup.Popup ' show the menu at mouse position
- Case "M1"
- Print "Menu 1 was selected"
- Case "M2"
- Print "Menu 2 was selected"
- Case "M3"
- Print "Menu 3 was selected"
Posted
Trainee
-EDIT-
Yes, works perfect, thanks again for your time
Posted
Guru

LiveFreeDead said
Thank you, I'll give it a go and see if it works like I intended. I was getting close but was stumped.
You're welcome.
PS. if you want example code try the software farm (a link is on the gambas IDE welcome screen) there's tons of example software there from pretty simple to pretty advanced
plus there's also programs on the wiki /app - Gambas Documentation
Posted
Trainee
I have a few bugs I can report, is there somewhere I should do that? BTW I found work arounds, but I am always for making tools as bug free as we can.
Posted
Guru

LiveFreeDead said
Software Farm will give me what I need to find in the future, I hope to not have to bother you guys too much.
I have a few bugs I can report, is there somewhere I should do that? BTW I found work arounds, but I am always for making tools as bug free as we can.
The bugtracker is at Connexion you register then can report bugs there.
also see this page…
/doc/report - Gambas Documentation
You should peruse the wiki some more though. lots of info there
(the link i posted above for reporting bugs is on the main page)
But don't worry about asking questions , that's what we are here for
You just said you wanted examples , so there's examples
Posted
Trainee
The plan is to Have
Select -
- All
- None
- Invert
Hide
- Portable
- Integrated
Load Preset
Save Preset
.
.
.
So a Sub menu for each action and a few root menu choices, like loading from a preset etc. so Sub menu's I assume would require a 2nd main menu with it parented to the 1st main menu?, I could still use the same POP action with a different name applied?
Posted
Trainee
The trick was giving the root menu it's Text and making it not hidden and populate it with items, then it passes to POP_Click and did it's thing
Posted
Guru

LiveFreeDead said
Yep I figured it out, was fairly easy
The trick was giving the root menu it's Text and making it not hidden and populate it with items, then it passes to POP_Click and did it's thing
but if it's not hidden then it always shows in the applications menubar so I don't think that was the trick, just a workaround.
(it's fine if you want it on the applications menubar)
Sub menus are done just by changing the parent when creating them.
Eg for your menus.
Select -
- All
- None
- Invert
Hide
- Portable
- Integrated
Load Preset
Save Preset
Code (gambas)
- hSubParent.Text = "Select"
- ' add the next ones to hSubParent not $hPopup
- hSub.Text = "All"
- hSub.Name = "mnuSelectAll"
- hSub.Shortcut = "Ctrl+A"
- hSub.Name = "mnuSelectNone"
- hSub.Text = "None"
- hSub.Name = "mnuSelectToggle"
- hSub.Text = "Invert"
- hSubParent.Text = "Hide"
- hSub.Name = "mnuHideP"
- hSub.Text = "Portable"
- hSub.Name = "mnuHideI"
- hSub.Text = "Intergrated"
- ' the last 2 are children of the main $hPopup
- hSub.Name = "mnuLoadP"
- hSub.Text = "Load Preset"
- hSub.Name = "mnuSaveP"
- hSub.Text = "Save Preset"
Posted
Trainee
Please if you have contact with the site admin, could they enable my account manually, either LiveFreeDead or GlennChugg. I can use either as they both have correct credentials.
Thanks again for clarification on the menu systems of Gambas, I will finish off my project and see if I can help out around here in the forums, my methods are never as clean as yours, but if I can help when I do know something, I will
Posted
Administrator

LiveFreeDead said
I've tried to sign up to the bug tracker but my first attempt I never received the confirmation email, so this morning I tried again with my outlook address, I got the confirmation email, but when I click the link I got "Unable to activate account." I tried clicking it again with same results.
Please if you have contact with the site admin, could they enable my account manually, either LiveFreeDead or GlennChugg. I can use either as they both have correct credentials.
Have you tried logging in with your account at bugtracker?
If that doesn' t work subscibe to the user mailing list an report your problem there.
Then Benoit can take care of it
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Trainee
1 guest and 0 members have just viewed this.


