Hi,
How to activate, by code, the button of a (Desktop)Toolbar?
I tried without success:
Toolbar1.MyButtonName_Btn.Pressed = true
Thanks
Hi,
How to activate, by code, the button of a (Desktop)Toolbar?
I tried without success:
Toolbar1.MyButtonName_Btn.Pressed = true
Thanks
Donât try.
Make the button call a method: eg DoStuff1
And instead of trying to âpressâ the button in code, just call the method in code instead.
Thanks @Jeff_Tullin , but I prefer the method with a command like âPressedâ (or equivalent), which would save me from making too many changes in my code.
Curiously, the command Toolbar1.myBtnName.Pressed = true, does select the button but does not trigger the Toolbar1.pressed event!!!
You are confusing events vs state.
Itâs unfortunate that someone at Xojo chose to keep the property named Pressed in the API 2 version of the button as it just causes confusion. The Pressed property that you are setting is just about appearance and has nothing to do with calling any code. Events cannot be âcalledâ the way methods can, so @Jeff_Tullin got it right, if you want to be able to âpressâ a toolbar button from code, you will need to put that code into a method.
Thatâs how VB did it as I recall.
But it ties your code to the UI / window on which the button exists
Using a common method allows you to use the same code in many areas of your app without having to duplicate the code.
For instance, a menu, or a completely different window.
You want Button_clicked and something that calls button_clicked.
I say Both Button_clicked and something should both call the DoTheThing method.
They have one line of code each, and the method is the same as the original button_clicked code.
But if you donât want to do that, I wonât try to convince you.