I agree with Rudolf that your approach seems “awkward”.
To an extent, perhaps the Language Reference is not a clear as it could be. See the LR “Notes” section where it states: "Colors are often used to assign colors to properties of type Color. Use the RGB, HSV, or CMY functions to assign a color to an object or use the format:
&cRRGGBB "
I would suggest stop reading in the middle of the last sentence:
“Use the RGB, HSV, or CMY functions to assign a color” . This is what Rudolf suggested. Building up a string to express a color literal or hex color is “awkward”. For my part, I believe I have always used R,G,B’s to express color and rarely if ever used Hex colors or color literals.
See the RGB, HSV, or CMY entries under “Shared Methods”. Note that there are also RGBA and HSVA methods listed, though by my reading, these are exact equivalents… both of these (and CMY) will take a 4th parameter “a” as Integer to handle the Alpha
I would also suggest a few changes to Rudolf’s code:
Rem New XOJO AP12.1
Var c As Color
Var b As Boolean
c= textarea1.BackgroundColor
b = Color.SelectedFromDialog(c, “Select a Color”)
// textarea1.BackgroundColor = RGB(c.red,c.green,c.blue,slider1.value)
// note that the RGB() function has been deprecated in 2019R2 in preference the the following:
textarea1.BackgroundColor = color.rgb(c.red,c.green,c.blue,slider1.value)
// R2.1 will not complain, but you may get warnings in the future
// note that I’ve left off the 4th parameter for transparency to be handled in the valueChanged event
// of Slider1
// Slider1.minimum = 0
// Slider1.maximum = 255
As noted above, I assume that one would want to change the alpha color component in the
ValueChanged event of Slider1:
Var c As Color
c= textarea1.BackgroundColor
textarea1.BackgroundColor = RGB(c.red,c.green,c.blue,slider1.value)
// Slider1.minimum = 0
// Slider1.maximum = 255