So, in my Paint event, I declare my button colors as variables and pass the actual Hex color codes from the button’s constructor. For example:
Paint Event:
linearBrush.GradientStops.Add(New Pair(0.0, NormalGradientStartColor))
Constructor:
NormalGradientStartColor = &cCBBFB3
According to the Debug log, the Paint event sees all color values as Hex color codes only with a leading “&h00” (for example: &h00CBBFB3). This results in the button colors being black. Does anyone know why this is happening?
Thanks!
Basic questions:
- What platform are you on?
- What Xojo version are you using?
There was an issue with color codes a long time ago when the Alpha channel was added, but if foggy memory serves that had something to do with setting property values in the IDE inspector.
I haven’t seen this behavior myself. Can you reproduce it in a simple project?
1 Like
You know what’s funny: When I put my simple project together and tested it, the behavior was no longer ocurring. So it’s something in my main project that’s causing the issue. But thanks for asking for a simple project! At least I now know where to start tracking down the problem.
Oh… and I’m on the MacOS platform and using version 2024 Release 3.
Wait, I just realized that the Debug log still indicates that the Paint event sees the Hex colors with the leading “&h00,” it’s just not translating into a problem when the button is rendered. I guess that simplifies the problem a bit.
That’s the expected output for the alpha channel that you’re seeing. ToString converts the color value to an integer then to a string where the first value is alpha, then red, green, blue. If you inspect the color value in the debugger, you’ll see that it is correct:
var c as Color = &cCBBFB3
var stringValue as String = c.ToString
var h as String = "#" + Hex( c.Red ) + Hex( c.Green ) + Hex( c.Blue )
break
1 Like
Ah, so that explains it. When I used the Str method on the color variable for the Debug Log, it returned the string value which gave me the alpha value. That’s awesome, Anthony. Very useful. Thanks so much!