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!
On a new card, make a new field. The backColor of that field is likely to be empty, since it inherits the color of the card, which probably has none. Open the "colors" tab of the inspector, and select "backGround fill". Bring the slider from full black all the way left and hit "OK". It looks like nothing has changed, but if you ask for the backColor of the field you get "255,255,255" or "white".
There are several colors associated with a field, like the "foreColor", which is the color of the text in that field.
on mouseUp
answer color
if it is empty then exit mouseUp
-- it contains the color as RGB, for example (0,0,0) black
repeat for each item aDezimalColor in it
put format("%02s",(baseConvert(aDezimalColor, 10, 16))) after tResult
end repeat
put "#" before tResult
-- tResult contains the color as HTML Hex, for example (#000000) black
-- set the backgroundColor of grc 1 to tResult -- you can set the colors in LC via HTML hex colors
put tResult into field 1
end mouseUp
I tested it with a web HTML color tester and by setting the background color of a graphic and it worked. No guarantees though...
function ConvertRGBToHexColor pRGB
local tHexColor
put "#" into tHexColor
repeat with j = 1 to 3
put format("%02X",item j of pRGB) after tHexColor
end repeat
return tHexColor
end ConvertRGBToHexColor
richmond62 wrote: Thu Feb 17, 2022 2:19 pm
Oddly enough . . .
You can set the backgroundColor using an HTML-style colour.
The snag is that there does not seem to be a way to read the backgroundColor directly
in HTML-style format.
If you set the backgroundColor of a graphic via a RGB-triplet you will get a RGB-triplet when trying to read the backgroundColor.
If you set the backgroundColor of a graphic via an HTML Hex-color you will get a HTML Hex-color when trying to read the backgroundColor.
To convert from an HTML Hex-color to RGB then you can use the old trick using the backgroundPixel as mentioned in Tim Bobo's lesson
on mouseUp
answer color
if it is empty then exit mouseUp
-- it contains the color as RGB, for example (0,0,0) black
repeat for each item aDezimalColor in it
put format("%02s",(baseConvert(aDezimalColor, 10, 16))) after tResult
end repeat
put "#" before tResult
-- tResult contains the color as HTML Hex, for example (#000000) black
-- set the backgroundColor of grc 1 to tResult -- you can set the colors in LC via HTML hex colors
put tResult into field 1
end mouseUp
I tested it with a web HTML color tester and by setting the background color of a graphic and it worked. No guarantees though...
If you set the backgroundColor of a graphic via an HTML Hex-color you will get a HTML Hex-color when trying to read the backgroundColor.
What I am refering to (and this may be beside the OP's point [but, as you know, I have never let that get in my way])
is that unless a backgroundColor has been explicitly set using an HTML hex colour