Does Xojo have a two-state icon/picture button?

A common UI item I use is the two (or three) state icon button. I often need a DIFFERENT image to indicate the button is in a pressed state, for example a “lock” button that displays either a “locked” icon or an “unlocked” icon. Bonus if it can support a third state (useful for items like text attributes). I need to control the drawing of the frame, because often these types of icons have no frame. I didn’t see anything like this in the Xojo library, but being a Xojo newb I could easily have missed it?

Use a canvas and the MouseDown/MouseUp pair of events and a static state variable to swap the canvas’ BackDrop. That will allow you to create up, down, pressed, released (or even hover) and multiple states.

Search the forum:
https://forum.xojo.com/38501-pictures-as-buttons

I have a crude example at: http://www.cmas-net.org.uk/rslug/Eg-1-CheckboxControl.zip

All excellent answers.

@Chris Carter – your example wasn’t all that crude. Probably the only thing I would add would be some test to see if the mouse is STILL INSIDE the bounds of the icon/picture button when the mouse button goes up, so it would change the icon/picture back to the unchecked picture the moment the mouse is no longer inside the control bounds.

So this kind of control seems like a fairly easy lift in Xojo, but I still think its so common that it should be made part of the standard set of built-in controls.

This is not the only missing thing…

[quote=356522:@Stephen Greenfield]All excellent answers.

@Chris Carter – your example wasn’t all that crude. Probably the only thing I would add would be some test to see if the mouse is STILL INSIDE the bounds of the icon/picture button when the mouse button goes up, so it would change the icon/picture back to the unchecked picture the moment the mouse is no longer inside the control bounds.

So this kind of control seems like a fairly easy lift in Xojo, but I still think its so common that it should be made part of the standard set of built-in controls.[/quote]

Very glad it helped… My particular logic on mouse-up & not bothering to track moves outside was simply what I actually wanted in the original (touch screen) application I had written which I lifted the example from - screen shots from that are in powerpoints, along with some other examples in the same folder on the web… IE at: http://www.cmas-net.org.uk/rslug