I would like to be able to retrieve the color value of a label’s TextColor. I have the following control hierarchy:
lSource As Label
I have tried pulling the value with:
wMain.lSource.TextColor.ToString // which completes
newColor = wMain.lSource.TextColor // also autocompletes
And both return an error of “This item does not exist” with regard to wMain.lSource
Is there no way to determine the current TextColor of a Label?
What version of Xojo? In 2021r3 I can get the textcolor of both a label and a desktoplabel. Is it possible you have an instance of wMain that’s called something else when you run it? Where are you trying to call your code?
I am trying to override the IsDarkMode so that we can gain some form of sanity on Linux. Since a Label is properly changing depending on the user’s Theme settings, I thought to override IsDarkMode as follows:
If SomeLabel.TextColor is Greater than mid-gray Then
Bingo! I no longer use Implicit Windows instances. Not enough coffee on a Saturday coding evening!
Nope - that’s still resulting in the same error.
I created a new label and that one is properly returning the TextColor -
One more for issues bringing an API-1 project into API-2 land …
This is not possible because it seems that the TextColor returned is the color set at design time, not the current color of the control …
@Christian_Schmitz - would you have a function/method that could look at the current color rather than the design color for an situation like this?
I don’t get the TextColor but only set it to what I need:
if self.Control(currentControl) isA Label then
if doEnable then
Label(self.Control(currentControl)).TextColor = colors.getMainColor
Label(self.Control(currentControl)).TextColor = colors.getDisabledLabelColor
I started a project in 2021r3, dragged a label onto the window leaving the color set at black, then put this in the window opening event:
label1.TextColor = &c990000
var labelColor as Color = label1.TextColor
label1.Text = labelColor.ToString
The label text changes appropriately. I changed the desktoplabel to a label and it still works. Am I misunderstanding what’s going on?
That’s not what I’m trying to do - Because Color.IsDarkMode is basically a NoOp on Linux, I need to determine if the platform Theme has changed the Text color based on the Dark/Light mode in effect at the moment. In this case, the TextColor is &c00000000 at design time, so the text is displayed as Black if the Theme is in light mode and white (or nearly white) in dark mode.
This is why I’m looking at the TextColor of a Label - Labels do follow the theme because they are native GTK objects unlike Canvas, ListBox, and others that we must manage the colors at runtime.
But, I still need to determine what the theme is set to display to allow me to make that choice.
Ah, I totally missed the bit about dark mode and IsDarkMode not being supported on Linux. Sorry about that. Hopefully Christian or a linux guru can help you find an appropriate call for that.
The embarrassing part is I “am” that Linux guru
The problem is that there is no way in GTK to get the theme info. most app authors solve this by providing a preference switch instead of automatically switching.
Fixed so far as discovering, not to determine why I can override Color.IsDarkMode with my only local IsDarkMode function.
Dim shot As Picture
Shot = ScreenshotRectMBS(Me.Left + 2, Me.Top + 40, 25, 25)
Dim rgbs As RGBSurface = Shot.RGBSurface
Dim newColor As Color = rgbs.Pixel(5, 5)
InDarkMode = newColor.Value < .5
InDarkMode = Color.IsDarkMode