I'm dynamically adding Labels to panels in my code.
Something I want to do is be able to outline the font so that it can stand out from the background color of the panel.
The problem is I don't know how to create a outline for my font or even a shadow effect in C# using Winforms.
Anyone know what I should look at or can point me in the right direction? If you don't understand what I mean, the following picture is what I would like: (the Outer lining)
I think you have to custom paint your own control. Here is an example for a
Label
. Note that it's just a demo, you should try finding out more on custom painting in winforms:You can change the outline color via
OutlineForeColor
property, you can change the outline width via theOutlineWidth
property. When you change these properties in the designer, the effect is not applied immediately (because there is not any code to do that, I want to keep it short and simple), the effect is applied only when the form is focused.What you can add more is mapping the
TextAlign
to theAlignment
of theStringFormat
(namedsf
in the code), you can also override some event raising methods to add more control over the look and feel (such as to change theForeColor
when the mouse is over the label...). You can even create some shadow effect and glow effect (it requires a little much more code).