Popup Menu with Graphic Sub

There was a conversation of a way to substitute of having a Graphic Icon in a PopupMenu with a Bevel Button in the Mouse Down Event. This used the code Below. It works perfect to create the icon & text to give popup menu effect.I just had to adjust the X, and Y location for the PopUp. My next big challenge is getting it to select one of the 4 menu Items. I tried the Bevel Button Mouse Up Event and ContextualMenuAction Event. I could not get the MenuItem Event to work.

Is there any special trick make the MenuItem Action Event to work?

dim base as new MenuItem
Dim Item1 as new MenuItem
Item1.Text = “Item 1”
Item1.Icon = pic1

Dim Item2 as new MenuItem
Item2.Text = “Item 2”
Item2.Icon = pic2

base.Append (Item1)
base.Append (Item2)

dim m as new menuitem

m = base.PopUp

The code should be in BevelButton Action event I think.

I’ve done it in a desktop project a while ago. Works fine and easy.
Later, I decided to have less buttons on a form and work with Contextual menu’s (right click) instead , which works in fact the same. The bevelbutton itself behaves just a bit different on Mac vs Windows, so it’s not my favorite control to use.

I tried the Action Event and there is nothing for hitItem for menus so it has to be the ContextualMenuAction event.

The ContextualMenuAction Event documentation show syntax function - ContextualMenuAction(hitItem as MenuItem) As Boolean

I’m not sure how to interpret how to write the code in the event. Does the Boolean mean menuItem selected True or False

In the the bevelbutton ContextualMenuAction event I’m using this code below to select one of the four Item1-4 menuitems. It does not work. There is another that has hitItem.tag as Varient. My Question? What am I doing wrong in the code below and how do I make it work to get it to select one of the 4 meniItems. (Thanks. I’m an old VB6 procedural Basic habit guy gradually interpeting Xojo OOP)

ItemString = hitItem.Text

Select Case ItemString
Case “Item 1”
'Selected Item
Case “Item 2”
'Selected Item
Case “Item 3”
'Selected Item
Case “Item 4”
'Selected Item
End Select

Extending & combining your code

[code]dim m as new menuitem

m = base.PopUp
If m <> Nil Then
Select Case m.text
Case “Item 1”
'Selected Item
Case “Item 2”
'Selected Item
Case “Item 3”
'Selected Item
Case “Item 4”
'Selected Item
End Select
End If
[/code]

menuItem.popup is modal so therefor you can use the result immediately.

And @Beatrix Willius is correct use the action event.

Thanks for your reply Wayne. I tried the this code in the BevelButton action event. The action event is still not firing. I even set a breakpoint in the debug to make sure.

Just in case I deleted all the other unused BevelButton events I tried but the Mousedown and Action events and still not working

dim m as new menuitem
dim base As menuItem

m = base.PopUp
If m <> Nil Then
Select Case m.text
Case “Item 1”
'Selected Item
Case “Item 2”
'Selected Item
Case “Item 3”
'Selected Item
Case “Item 4”
'Selected Item
End Select
End If

Jeffrey: please use code formatting, when you post your code. The Action event of a BevelButton MUST fire. What happens when you do a new project, just add a BevelButton and the Action event with a “beep”?

Sorry about the Code formatting, didn’t know about the code tags. So Beatrix for troubleshooting - I deleted the MouseDown Event with the icon & text menu code and commented out the above code and added a beep and the action event worked. Then I put back the MouseDown MenuCode and kept the Beep in the Action event and it does not work.

So it proves the menu code in the MouseDown is effecting the Action Event. I’ll put in the exact MouseDown code that does create an Icon and Text Popup type menu. Also the action Event Code. Maybe someone could recognize anything that could be effecting the Action Event Handler. Thanks for your great troubleshooting idea.

'MouseDown Event Code
  Dim base as new MenuItem

  Dim Item1 as new MenuItem
  Item1.Text = "Rose Wood"
  Item1.Icon  = RoseWoodGtr6FrtBrdRightSmIcon
  
  Dim Item2 as new MenuItem
  Item2.Text = "Ebony Wood"
  Item2.Icon  = EbonyWoodGtr6BrdRightSmIcon
  
  Dim Item3 as new MenuItem
  Item3.Text = "Blue Wood"
  Item3.Icon  = DarkBlueGtr6FrtBrdRightSmIcon
  
  Dim Item4 as new MenuItem
  Item4.Text = "Mono Chrome"
  Item4.Icon  = MonoChromGtr6FrtBrdRightSmIcon
  
  
  base.Append (Item1)
  base.Append (Item2)
  base.Append (Item3)
  base.Append (Item4)
  
  dim m as new menuitem
  m = base.PopUp(WinFrtBrdOpt.Left+40, WinFrtBrdOpt.Top+94)

'Action Event Code
  'Test Beep
  Beep
  
  dim m As MenuItem
  dim base as MenuItem
  
  m = base.PopUp
  
  
  If m <> Nil Then
    Select Case m.Text
    Case "Rose Wood"
      cvsFrtBrdSeleted.Backdrop = RoseWoodGtr6FrtBrdRightIcon
      
    Case  "Ebony Wood"
      cvsFrtBrdSeleted.Backdrop = EbonyWoodGtr6GtrtBrdRightIcon
      
    Case "Dark Blue"
      cvsFrtBrdSeleted.Backdrop = DarkBlueGtr6FrtBrdRightIcon
      
    Case "Mono Chrome"
      cvsFrtBrdSeleted.Backdrop = MonoChromGtr6FrtBrdRihtIcon
      
    End Select
    
  End If

ALL of your code needs to go to the Action event. The MouseDown knows nothing about what happened in the Action event.

[code] Dim base as new MenuItem

Dim Item1 as new MenuItem
Item1.Text = “Rose Wood”

Dim Item2 as new MenuItem
Item2.Text = “Ebony Wood”

Dim Item3 as new MenuItem
Item3.Text = “Blue Wood”

Dim Item4 as new MenuItem
Item4.Text = “Mono Chrome”

base.Append (Item1)
base.Append (Item2)
base.Append (Item3)
base.Append (Item4)

dim m as new menuitem
m = base.PopUp(me.Left+40, me.Top+94)

If m <> Nil Then
Select Case m.Text
Case “Rose Wood”
MsgBox “Rose Wood”

Case  "Ebony Wood"
  MsgBox "Ebony Wood"
  
Case "Dark Blue"
  MsgBox "Dark Blue"
  
Case "Mono Chrome"
  MsgBox "Mono Chrome"
  
End Select

end if[/code]

Please note that you can use “me” instead of hard coding the name of the control “WinFrtBrdOpt”. And you really can use vowels in the name of the controls :wink:

That’s not entirely true. If base was a property of the window then you could build the menu (base) once on the open event of the control or window. Even better you could create a custom control and encapsulate the property & build method in that class which of course makes it available across the entire project.

@Wayne: let’s get the basics done and do the advanced stuff as second step.

@Beatrix Willius The OP is a member of the alpha group, normally I wouldn’t have moved to that level of sophistication.

The problem is BASE is defined in the MOUSEDOWN event, and is out of scope by the time the ACTION event fires… which is why I believe Beatrix said is “must all go in ACTION”

Thank guys I got it to work . I just had to modify the Menu Item Code to run once.