PopupMenu Icon

Hello, I want to know if there’s a way to add icons to the Rows of a PopupMenu. Thanks in advance

Mac? Win? Linux? iOS? Web?

just to be sure.

Mac and Windows

Use a Listbox and a button.

I asked same question a couple of days ago.
Ended up using a button and a real menu, displayed as a popup

for Mac and with MBS Plugins this seems to work:

[code] // get cocoa view for the popupmenu
dim p as NSPopUpButtonMBS = PopupMenu1.NSPopUpButtonMBS

// find a menu entry
dim it as NSMenuItemMBS = p.itemAtIndex(0)

// get a picture
dim pic as Picture = LogoMBS(500)
dim img as new NSImageMBS(pic)
img.setSize 16,16

// and assign icon
it.image = img[/code]

[quote=256431:@Jeff Tullin]I asked same question a couple of days ago.
Ended up using a button and a real menu, displayed as a popup[/quote]

I did not realize the icon would shown in a ContextualMenu. That sounds like easier than a ListBox.

So I put a BevelButton and I add this on the “ConstructContextualMenu”

[code] me.DeleteAllRows

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[/code]
the problem is that it doesn’t display anything, and it also has the “HasMenu” option select

[quote=256435:@Federico José D’Andrea]So I put a BevelButton and I add this on the “ConstructContextualMenu”

[code] me.DeleteAllRows

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[/code]
the problem is that it doesn’t display anything, and it also has the “HasMenu” option select[/quote]

This would show up with a click of the secondary mousebutton :wink:

HasMenu is for a normal menu

BevelButton.Open

me.DeleteAllRows me.addrow "Item 1" me.addrow "Item 2"

[quote=256447:@Axel Schneider]HasMenu is for a normal menu

BevelButton.Open

me.DeleteAllRows me.addrow "Item 1" me.addrow "Item 2"[/quote]
But how can I add icons to this rows?

you can use BevelButton.Mousedown

[code] 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[/code]

[quote=256456:@Axel Schneider]you can use BevelButton.Mousedown

[code] 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[/code][/quote]
Thanks you so much!

Displaying the popup is only half the work.

Here is a complete project which also shows how display it in the proper place, and how to get the selected value:

popupwithicon.zip

[quote=256464:@Michel Bujardet]Displaying the popup is only half the work.

Here is a complete project which also shows how display it in the proper place, and how to get the selected value:

popupwithicon.zip[/quote]
Yeah, I know, but this part I know how to do it, I added to the both items Item1.Tag="0" Item2.Tag="1"
and then I put:

Dim m As new MenuItem m = base.PopUp If m <> Nil Then If m.Tag="0" Then...

Thanks so much!

The Retina Kit has functions for this on OS X.
http://www.ohanaware.com/retinakit/

You can download the trial and test it out.

For Mac only, see MacosLibrary: additional Modules > Class Extensions > PopupMenuExtension > Method “AddRowWithTagAndPicture”.