menuitem icon

hi :slight_smile:

if i add a menuitem with code, how can i set the icon in the same line? for a listbox kontext menu for example

Just assign the picture you want to the Icon property of the MenuItem.

“in the same line”
Same line of code, as in one command to create the menu item… you can’t
Same line as in menu text and icon on the same display line, that is what Paul is referring to

Hmm i create a contextmenu on a listbox like thos

base.Append(New MenuItem("Open Website of the Addon")) base.Append(New MenuItem("Support the the Addon"))

and here i cant add an icon?

Save the reference:

Dim openMenu As New MenuItem("Open Website of the Addon")
openMenu.Icon = MyOpenIcon
base.Append(openMenu)

Thank you so much :slight_smile:

The other way I’ve used in the past…

base.Append(New MenuItem("Open Website of the Addon")) base.item( base.count-1 ).icon = MyOpenIcon

or

Function myMenuItem(caption as string,icon as picture) as menuitem
dim m as new menuItem(caption)
m.icon=icon
return m
END FUNCTION

then reuse it as required

base.append(myMenuItem("open website",myOpenIcon)

One question… how can i deactivate a context menu ?

set its enabled to false

and how do i do that with base.append(myMenuItem(“open website”,myOpenIcon) context

you need to keep a known reference to each menu item

[code] 'create the context menu
Dim openEdit As New MenuItem(“Edit Addon”)
openEdit.Icon = resources.toPic(resources.icon_context_edit16)

Dim openDelete As New MenuItem(“Delete Addon”)
openDelete.Icon = resources.toPic(resources.icon_context_del16)

Dim openWebsite As New MenuItem(“Open Website of the Addon”)
openWebsite.Icon = resources.toPic(resources.icon_context_web16)

Dim openPatreon As New MenuItem(“Support the Addon”)
openPatreon.Icon = resources.toPic(resources.icon_context_pat16)

If Me.RowFromXY(x, y) >= 0 Then
base.Append(New MenuItem(openEdit))
base.Append(New MenuItem(openDelete))
base.Append(New MenuItem("-"))
base.Append(openWebsite)
base.Append(openPatreon)
End If
Return True[/code]

i do it like this :slight_smile:

openwebsite.enabled = false

hm but why isnt this working? listbox1.openwebsite.enabled = false i tried it like this already

openwebsite should have nothing to do with listbox1
it should be a variable defined in a scope outside of any specific control
unless you have subclassed the Listbox control then that is another story…

This is in the ConStructContextualMenu

I’ve been staying out of this on difference of opinion, but if you promise me you won’t put icons in a menu ever in your lifetime as a developer, I’ll write you a demo project that shows how this all works together.

Uhm o.o" why you dont like icons there, on windows this is ok :smiley:

i create a crappy workaround with a integer to check if a prozedure is running. But i would really like to hide the whole menu for some times.