Adding icons to MenuItem

Only pictures loaded into the Xojo project can be used as icons on the MenuItem.Icon property?
Is it not possible to create a Picture, with, lets say, 16x16 pixels, draw something in it with the Graphics commands and assign it to the MenuItem.Icon property?

Have you tried? It’s working here for items other than FileQuit. It doesn’t appear necessary to retain the Picture object.

1 Like

create a method and in that create a Picture and return it for the Icon Property, should work.

I tried this and it didn’t work:

copy_from.RemoveAllRows

Var i As Integer
Var name As String
Var item As DesktopMenuItem
Var thumbnail As Picture

For i = 0 To 9
  thumbnail = New Picture (16,16)
  thumbnail.Graphics.DrawingColor = &c00aa00
  thumbnail.Graphics.FillRectangle 0,0,16,16
  item = New DesktopMenuItem
  item.Text = "Test"
  item.Icon = thumbnail
  copy_from.AddRow(item)
Next

copy_from is a DesktopPopupMenu.

Ah, it wasn’t clear that you were working with a PopupMenu. The control previously did not accept MenuItems for AddRow, and I think this is leading to the confusion.

PopupMenus, at least in Xojo, do not support icons. From the documentation for MBS it appears the plugin can help, but I haven’t tested that - perhaps @Christian_Schmitz can chime in with an actual confirmation on that one.

Update: I have filed a ticket for improved behavior regarding this method. #79184 - DesktopPopupMenu.AddRow accepts a MenuItem, but does not use any of the features besides Text and Tag

3 Likes

Yes, we have a sample project for this:

Uses NSPopUpButtonMBS and NSMenuItemMBS classes.

I changed it into a Popup menu, created dynamically, on a Mouse Down event of a Canvas with a custom icon as the Background.
But it would be great to have the DesktopPopupMenu use all the MenuItem options.