labels always transparent ? (Windows)

Hi
I see that labels are always transparent even if you turn transparency off in the inspector.
They become transparent at runtime, during ide they behave “correctly”.
Is it a bug ?

any tips to make them not transparent because I need to see their borders and space, thanks

regards

Here is how to create a non transparent label control :

  • Drag a Container control in the project in the left pane (not on a page)
  • Select the container control. It appears as a box
  • Set its HasBackColor to Yes in the inspector
  • Set the color you want underneath. It will not show in the IDE but will show when you run.
  • Drag over it a label
  • Make the Container control size the same as the label
  • Lock the label on all sides (in the inspector)

Now you drag the container control from the left pane onto a window.

You set the size as usual in the IDE or in code with nameofthecontrol.width and .height (for the autosize I taught you for instance), and address the content by nameofthecontrol.Label1.Text. For instance ContainerControl11.Label1.Text

Creating controls is the way to get features not normally present in regular controls.

are you planning the implement the transparency and the autosize soon or is it something that you don’t give much importance to ?
just wondering

Horacio, I often use the comparison with giving a man a fish versus teaching him how to fish. I just tried to teach you how to fish by building your own controls.

Once you understand how to do that, you can support all sorts of features. The autosize I gave you can be applied to this by adding to the container control a method, for instance SetText(string) where you set the size of the control and put the string in Labe1.Text at the same time. If instead of setting the Container Control background color you create a picture to place in its backdrop, you can control its transparency. See http://documentation.xojo.com/index.php/Picture.Constructor(width_as_Integer,_height_as_Integer) to create a picture with a level of transparency, and http://documentation.xojo.com/index.php/Graphics.FillRect to fill it up with a color.

With the same Container Control technique, you could create an autosizing button too, for instance.

[quote=114159:@Horacio Vilches]are you planning the implement the transparency and the autosize soon or is it something that you don’t give much importance to ?
just wondering[/quote]

In case you where asking if Xojo Inc was going to implement the features you talked about, I have no idea. I am just a Xojo user like you, trying to provide the help I can by offering methods and workaround I usually test myself before posting. And I can tell you that the features you wish implemented can be through the method I described, I just tried the transparency for a Container Control backdrop image.

You can fill a feature request by using Feedback, or search to see if someone else requested it. I just did that for ‘autosize’ and found two entries. In one from 2007, the same kind of approach I offered is outlined.

If you search ‘label transparency’ you will find 16 cases, including 3 feature requests which do not match what I think is your request. About that, though, when you drag a control and don’t set it to Transparency On, it’s background is opaque grey. Windows 8.1. Is that not the case for you ?

I think you’re confusing transparency with background. If you want a background colour use the above suggestion, if you want it to be the system Window colour transparency = false

I can’t edit the above. Think of transparency meaning draw the things it’s place on or not. So if you put a label (100X100) on a Red Filled Canvas and transparency = False. The Red under the label will not be drawn at run time. You will be able to see the Window background. If Transparency = True then the Red will be drawn and you will see text on the canvas, not a ‘hole’

Good you make the distinction. Indeed, if Transparent=False the default window background color should show. But it is not so clear reading from the OP first post, where he says that apparently, even with that setting, he finds the label to be transparent.

And yes, the workaround I offer sets the background color, which is different.

I was talking about the label background that is never transparent even if you set it as transparent on the inspectir

Horacio, you get me confused. From your original post, I had understood that when you set the label NOT transparent, it was transparent anyway.

From what you just wrote, is it that when you set a label to transparent, it remains grey ?

Just curious.

Below is an example of how label transparency works.
I placed a canvas on the form and put a color into it.
I put two labels on the canvas one with and one without transparency.
Non-transparent labels always take on the window color not a custom color.

If you want a different background then you need to use Michael’s good suggestion above.

This is a native behavior on windows. And currently Xojo does not emulate the functionality on OSX and Linux.
So Label.Transparent state is just ignored on those platforms, being transparent all the time.

Indeed Mac and Linux Label is always transparent. But the method I posted works just as well.

How can you talk about the label background. Labels do not have backgrounds. You need to get your head around that. See the Picture posted by Bob above? That’s not a background being drawn on the second Label, that’s not drawing the Canvas underneath, that’s why it’s the same colour as the Window. Label’s are not created to have backgrounds. You need to put a label on something that will paint colour and set the Transparency to False to make it look like there is a background. No it probably won’t change in the near future in any language

I’m sorry but you are mistaken. The standard behavior for labels (in windows) is setting a background color, including a “transparent” color, the usual default is using the parent window color. So, it’s really painted. You can have whatever under the label and it will paint a background color over it (except of course a transparent color).

But I’m talking about Xojo, I’m not talking about what you can do in something like MSVS. In Realbasic before the ‘label’ was added, after the Label was added and in Xojo (I’m guessing I haven’t upgraded) there is no Background property so you can not have a background.
conversations online are never simple :slight_smile:

Internally there is, and is set as the current window parent color. But it’s not exposed. They chose to have the transparency option partially exposed and did not implemented the label background painting color selection for the opaque option. What we see is just a matter of choices the Xojo designers did trying to make their life easier in the cross platform world. I’m not happy with the inconsistency of this behavior, it should behave as expected on others too. The best way for me should be having the backcolor exposed and emulating the function on those who does not have it natively painting a rectangle behind. Xplat consistency. But this is just my opinion. ( Just for the curious, In terms of Win API there are SetTextColor(), SetBkColor(), and SetBkMode() )

In VS you also have border style, background image, and padding to mention a few

And autosize…

Feature requests are the best way. Or using Declares. Or building controls. Or using VS :wink:

Yes. But those Xojo designers opted to keep out. Label background transparency was exposed as a design functionality. It’s fair to expect it working in the IDE and runtime, xplat. Horacio post proves this occurs.