How do I change the icon of a button in code that has been created in the IDE?
Also while in the IDE, or at runtime?
And what specific type of button?
At Runtime so I can show alternate themed pushbutton icons
With MBS plugin:
dim nt as NSToolbarMBS = self.NSToolbarMBS
dim items() as NSToolbarItemMBS = nt.items
for each item as NSToolbarItemMBS in items
if Color.IsDarkMode then
if item.label = PrefsToolbarLocalization.kProxy then
dim theImage as new NSImageMBS(proxy_dark)
theImage.isTemplate = False
item.image = theImage
ElseIf item.label = PrefsToolbarLocalization.kFonts then
dim theImage as new NSImageMBS(pen_dark)
theImage.isTemplate = False
item.image = theImage
and so on. I have one set of ugly outline icons and one set of nicely colored icons.
If the button has an icon property, and you created it in the IDE, it has a name
eg button1
so just issue button1.icon = nameoficon
and button1.invalidate
if you clone the button at runtime, then it is part of a control array.
You would need to do something like button1(0).icon = nameoficon
Standard buttons do not have icons, however.
BevelButtons do- but naturally, they have been deprecated.
Just checking, you don’t use the IDE to create the initial Toolbar and that you create it all in code?
I don’t seem to be able to reference the icon property of the Toolbar button I create in the IDE
What does this mean?
Toolbar button
Thank you. Not a pushbutton, then.
Beatrix’s solution should work in this case.
Do you have the MBS plugins?
.Icon is not an option??
Have you tried it anyway (Jeff’s code, I mean)? If so what does the compiler have to say?
Try
ToolbarButton(TBNew).Icon = MyPicture
I create the toolbar in the IDE, but I have 3 sets of icons (light, dark, outline). Also I can change individual icons.
Ok I have both Beatrix and Martin T solutions working MBS took me a bit more to work out and Martin’s was probably what I was asking in the beginning but could wrangle with the correct syntax.
DesktopToolbarButton(Toolbar12.TBNew).Icon = New32_OS11
DesktopToolbarButton(ToolbarInstance.ButtonName).Icon = NewImage
Thanks