Label Text with Transparency

Hello everyone,

Is it possible to set a label’s text color with transparency ?

Label1.TextColor = RGB(0, 0, 0, 125) // not working for a 50% transparency :(

Thanks :slight_smile:

[quote=133391:@Walter Sander]Hello everyone,

Is it possible to set a label’s text color with transparency ?

Label1.TextColor = RGB(0, 0, 0, 125) // not working for a 50% transparency :(

You should post in Windows or OS X, to get adequate help.

Works fine here on Mac. On Windows, you may need to use GDI+, or employ a canvas instead of a label.

Yup, on Windows use app.useGdiPlus = true then it should work.

Keep in mind though, changing the text color like this (Windows 8.1) made the text blurry within the label.

@Michel Bujardet You’re right, it’s for both Win & Mac

@Eric Brown I have set app.useGdiPlus = true and the text has now 100% transparency for a TextColor = RGB(255, 0, 0, 127) … without the 127 value, it woks okay thought with no transparency at all. I on a Windows 8.0 machine.

[quote=133405:@Walter Sander]@Michel Bujardet You’re right, it’s for both Win & Mac

@Eric Brown I have set app.useGdiPlus = true and the text has now 100% transparency for a TextColor = RGB(255, 0, 0, 127) … without the 127 value, it woks okay thought with no transparency at all. I on a Windows 8.0 machine.[/quote]

I just tried on Windows 10 and 2014R2.1 with GDI+ on with 0,0,0,200 and I get a light transparent grey.

hmm, have just tried in different form and work okay.
Its a little bit buggy when the label is anchored inside a canvas, that’s where am struggling to make it work.

[quote=133410:@Walter Sander]hmm, have just tried in different form and work okay.
Its a little bit buggy when the label is anchored inside a canvas, that’s where am struggling to make it work.[/quote]

Tried again in Windows 8.1. Works fine.

Since you are using a canvas, why not simply DrawString in the canvas Paint event ?

Because I don’t know how to do that :smiley:

See http://documentation.xojo.com/index.php/Graphics.DrawString

The example cited can be applied right away in the canvas paint event with the transparent color you want.

@Michel Bujardet This canvas is for a fade-in / fade-out effect (backdrop) and the idea is the fade the text too which means the Paint will makes much sense.

A little bit off topic, but, is it a good practice to use DrawString to create a sharp text shadow ? 1 pixel offset in X and Y would be enough.

edit: and thanks :slight_smile: very helpful

[quote=133418:@Walter Sander]@Michel Bujardet This canvas is for a fade-in / fade-out effect (backdrop) and the idea is the fade the text too which means the Paint will makes much sense.

A little bit off topic, but, is it a good practice to use DrawString to create a sharp text shadow ? 1 pixel offset in X and Y would be enough.[/quote]

Yes, the shadow effect can be done by drawing it at an offset.

[quote=133418:@Walter Sander]@Michel Bujardet This canvas is for a fade-in / fade-out effect (backdrop) and the idea is the fade the text too which means the Paint will makes much sense.

A little bit off topic, but, is it a good practice to use DrawString to create a sharp text shadow ? 1 pixel offset in X and Y would be enough.

edit: and thanks :slight_smile: very helpful[/quote]
You can do all sorts with a canvas.

Works like a charm, thanks guys!