Change button background on mouse click

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Change button background on mouse click

Post by croivo »

Let's say my button has background image [picture1] and what I want to do is when I click on that button, the background image changes from [picture1] to [picture2]. How to change image background? The code should be something like:

Code: Select all

set the backgroundimage of me to [ImageName]
Regards,
croivo
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Change button background on mouse click

Post by FourthWorld »

If you use the button's icon properties this becomes very easy with automatic behavior - check out the Dictionary filtered for "icon" to see all the icon options available.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Change button background on mouse click

Post by croivo »

FourthWorld wrote:If you use the button's icon properties this becomes very easy with automatic behavior - check out the Dictionary filtered for "icon" to see all the icon options available.
Thanks :)
Here is my code now (if somebody wants to know):

Code: Select all

set the icon of me to [ImgID]
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Change button background on mouse click

Post by croivo »

Hello guys, I have question about how to change the background of text field when it is selected (active). I want to have, for example, green text fied but when user click with mouse on it (or with TAB key navigates to that field), it become blue. And when user click on some other field or on empty area, the background changes back to green.
Any ideas?
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Change button background on mouse click

Post by FourthWorld »

While only buttons have an icon property, all controls in LiveCode have many other properties to govern appearance, including foregroundColor, backgroundColor, foregroundPattern, and backgroundPattern.

The latter is what you're looking for here:

set the backgroundPattern of field "SomeField" to tSomeImageID
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Change button background on mouse click

Post by croivo »

FourthWorld wrote:While only buttons have an icon property, all controls in LiveCode have many other properties to govern appearance, including foregroundColor, backgroundColor, foregroundPattern, and backgroundPattern.

The latter is what you're looking for here:

set the backgroundPattern of field "SomeField" to tSomeImageID
I know for that, my problem is that I don't know what code to put instead of "on mouseUp" (i don't know how that line of code i called). How to know when text field is selected (active)?
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Change button background on mouse click

Post by jacque »

See the "focusIn" and "focusOut" entries in the dictionary. Or, depending on what your script does, you might use "openfield" and "closefield" and "exitField" instead.

Edit: I see that your field is editable. In that case use the open/close/exit field messages. Focus messages only work in locked fields.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Change button background on mouse click

Post by croivo »

jacque wrote:See the "focusIn" and "focusOut" entries in the dictionary. Or, depending on what your script does, you might use "openfield" and "closefield" and "exitField" instead.

Edit: I see that your field is editable. In that case use the open/close/exit field messages. Focus messages only work in locked fields.
That is exactly what I wanted. Thanks!
Post Reply