Hi everyone, I’m working with my program and I’m implementing some images to make them become buttons. Every time I click on the button I send a command to my Arduino to turn on the LED. Now, as it is structured, if I press ON it disappears and I turn on the LED, if I press OFF it disappears and I turn off the LED and it comes back ON. I can put these on each other and make it appear when I click. That is, initially OFF appears if I press enter the command and exit ON.
I used mousedown with:
Canvas5.Visible = false
Canvas6.Visible = true
June 24, 2019, 12:59pm
Is there a question in there someplace?
@Dave S, i want only 1 icon. How can to make this?
June 24, 2019, 1:43pm
put them in the same place, and only have one visible at a time
or have one “button” and switch the icon image on click
@Luka Jovic You can use a Canvas and draw one of the two icons depending on the current state:
If it is ON, draw the OFF icon
If is is OFF, draw the ON icon
June 24, 2019, 2:54pm
Add a Boolean Property to the Window containing the Canvas (the Button representation). Something like “LED1Status”.
Set the Property to On/Off according to the LED Status.
(following Code written from my mind, may contain errors)
In the MouseUp Event of the Canvas write something like:
LED1Status = Not LED1Status // Or True and False
btnCanvas.Invalidate // Makes the Canvas redraw (fire the Paint Event) ASAP
Return True // I think this is needed...
In the Canvas.Paint Event do something like this:
If LED1Status Then
g.DrawPicture(picON, 0, 0)
g.DrawPicture(picOFF, 0, 0)
@Sascha S LED1Status, how to declare?
June 24, 2019, 3:07pm
Boolean Property to the Window
Select Window on left panel, right click, add to window, property, type boolean, name LED1Status
June 24, 2019, 3:08pm
Just add a new Property to your Window in the Xojo IDE. Name it LED1Status and set it’s Type to Boolean and the default value to the Start Status of the LED.
I am not at a Dev Machine right now and can’t describe in more detail how to add a Property to a Window. But i’d HIGHLY recommend to read the user guide if you do not know already how to add a Property to a Window: