Set background color to a label?

I don’t see a property for this?

Do I need to place the label on a rectangle to get a background color?

Are you talking about a Label or a WebLabel ?

You know, to make it easier to answer your questions, you should post in the Web channel, when it is about a Web project.

Okay. I thought since I was a Xojo beginner, Getting Started was the place to be.

I’m testing out both Windows Desktop & “Windows” web stuff.

But this one is for a desktop app.

Thanks

Did you read: Introduction to Programming Book ?
(the projects are in the zip archive).

I read it and I went through all the tutorials. The problem is the book does not explain a whole lot. Sometimes you would do an example and say “oh great, that was easy”. But with no underlying explanation why it works or that certain code words are actually Xojo “key” words, etc. It’s also not indexed and the TOC is just chapter headings. So, yeah, it useful, but not as useful as it might be (not even close). Furthermore, i can’t remember all the various features and examples in the book off the top of my head, as nice as that might be.

For DESKTOP, there is no background color for a label

for macOS you can put a canvas under the label to provide a background color, but this doesn’t seem to work for WIndows, as the Label is opaque regardless of the “transparent” property (which seems to have no purpose for any OS)

Ok, thanks. Seems like a severe limitation in something really basic. I’ll have to play around and see if I can find a work around. Although I suppose, thousands of Xojo users have already tried to do that.

Use a Canvas…

But Dave S. says that won’t work in Windows.

Instead of a Label…

Okay, thanks. I haven’t tried the Canvas out yet. I will explore.

A label in windows will use the background color from any parent control (or container/window) that has the option to set a fill/background color.

So if you want a label with a red background, place a rectangle down, set its background to red then place a label over the top of that. When you run the project the label will then have a red background (the ide has a bug at the moment where it doesn’t show this at design time)

When you place the label on the rectangle ensure that the rectangle has a red highlight, this is an indication that the rectangle will be the parent of the label.

You can then adjust the rectangle and label size as required.

Let me know if you get stuck and I’ll throw up a quick video.

PS. Transparent labels are slightly different, please dont use those unless you have no other option as you will incur a performance hit (which may/may not be noticeable, depending on your window/features)

Peter, you can do what you want in Windows with a Rectangle and Label, the only “trick” is that you need to move the Label inside the Rectangle so it became the Label’s “parent”, this will force the Label to take the color from the Rectangle:

if the Rectangle is not the parent of the label then you will get something like this:

Edit: Julian explained this while I was creating the images. Follow his instructions and you get good results.

Julian & Alberto - Muchos Gracias!

Works like a charm.

See image for my little test in the lower left corner. It works even in the IDE!

I understand this is only a test, but what good is it to have a label with white text above a green background ? Who is just a Label ?

Is this GUI rules compliant ?

“GUI rules compliant”… there are no “rules”… just “guidelines” set forth by Apple and Microsoft. While there seem to be some who fancy themselves “GUI Police”… a developer is free to make their apps using any color scheme they see fit.

So perhaps Peter has a valid reason for a “green” label…

You’re a tough customer, Emile.