Adding font drop shadow possible?

Hey all,
Just curious if adding a ‘drop shadow’ to text in a Label was possible or not. Pure Xojo code preferred if possible. I did search the forums but didn’t find much of anything really. Using Windows 10, latest 2019 version.


Not in code. But to mimic it you can add a second label in light gray with a 1 pixel offset below…

Maybe…what would be example code of this in action?

Because overlapping Controls are not recommended, i’d suggest to use a Canvas and draw your String/Text 2 times. Draw it first with f.e. 50% lighter colors (or a light gray (grey?)) and then a second time with the correct colors 1 point/pixel moved on x- & y-axis.

In the Canvas Paint Event:

g.ForeColor = [Put your light Color for the Shadow here] g.DrawString("Hello world", 11, 131) g.ForeColor = [Put your main Color for the Text here] g.DrawString("Hello world", 10, 130)

Create your own Canvas Subclass. Add Public Properties for the Text and the Colors. Add them to the Inspector Behaviour and add Code in the Subclass Paint Event which draws the Text.

Thanks, Sascha. It (sorta) works. The thing is, I use custom fonts too, and it only seems to render in the ‘System’ font for a Canvas. Has anyone found a workaround for this?

Did you take a look into the Docs i posted? :slight_smile:

TextFont property: [quote]You can enter any font that is installed on the computer…[/quote]

g.TextFont = "Helvetica" // Your Font here please ;-) g.TextUnit = FontUnits.Point g.TextSize = 16

BTW: Can you please mark the Thread as answered. This will help others later to find a Thread with a solution. :wink:

(RightClick and Save as… Remove the “.txt” from the File. It should just be named “LabelWithShadow.xojo_xml_code”)

This is a Subclass of a Canvas prepared like described above, but with no Bells & Whistles. Just something to get you started with your own Shadowed Label Class. :slight_smile:

Drag & Drop the File into your Xojo Project into the Navigator.

I made a short video on how to create the Canvas Subclass and posted it in the Getting Started Section of this Forum. Nothing special, but… :slight_smile: