Click Button

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:

Serial1.Write("LED1ON") Canvas5.Visible = false Canvas6.Visible = true

Is there a question in there someplace?

Hi @Dave S, i want only 1 icon. How can to make this?

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

I try but not works.

@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

post what you “tried”

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:

Serial1.Write("LED1ON") 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) Else g.DrawPicture(picOFF, 0, 0) End If

@Sascha S LED1Status, how to declare?

Boolean Property to the Window
Select Window on left panel, right click, add to window, property, type boolean, name LED1Status

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: Windows — Xojo documentation