Setting toolbar button state at runtime

I have a toolbar button of the type “ToolStylePushButton”. When you click it it remains ‘toggled’ until you click another toolbar button.
I save the last toolbar button the user clicked so I can open the window in the same place it was during the last session. I have this all working fine but is there a property for ToggleState? I’d like to keep that button ‘pressed’ when the window loads.

My toolbar is called MainWindowToolbar and in the Window.Open event, I can do:

MainWindowToolbar.Item(Index)… and I get Caption, Name, Enabled, HelpTag & Tag.

  • nothing for Button State though.

Do we have that?

Probably need to cast
MainWindowToolbar.Item(Index)
to a ToolButton

if MainWindowToolbar.Item(Index) isa ToolButton then
   dim tmpToolButton as ToolButton = ToolButton(MainWindowToolbar.Item(Index))
  
      // now see tmpToolButton.Pushed  
end if

You forgot an ending parenthesis…

what I get for writing code in the forum

Thanks Norman! That worked perfectly.
Is that how you cast in Xojo? (like, does ToolButton(MainWindowToolbar.Item(Index)) cast the toolbar item at Index to a ToolButton?

ps I also forgot my ending parenthesis !

[quote=447938:@Rob Hallock]
Is that how you cast in Xojo? (like, does ToolButton(MainWindowToolbar.Item(Index)) cast the toolbar item at Index to a ToolButton?[/quote]
Yes and yes