TransparencyKey
works with a single color. When you use anti-aliasing to draw a round corner, the line color will be mixed with the background color so the color which you see is not exactly the Lime
, it's a mixture of Lime
and Gray
to make the round corner more smooth. So when you set TransparencyKey
to Lime
that color(s) will not be removed.
To have a high-quality alpha blend round corner, consider using Layered Windows. Create a bitmap with transparent background containing smooth drawing of round rectangle then using the technique which you can find in below post, make your shaped form:
Using a layered window can significantly improve performance and
visual effects for a window that has a complex shape, animates its
shape, or wishes to use alpha blending effects. The system
automatically composes and repaints layered windows and the windows of
underlying applications. As a result, layered windows are rendered
smoothly, without the flickering typical of complex window regions. In
addition, layered windows can be partially translucent, that is,
alpha-blended.
Important Note
The technique which described above is useful for creating a simple splash screen, but when you want to place some control on your form, you need to use a workaround.
Additional to your main form, you can create another window with the WS_EX_LAYERED
style and use that to show the alpha blended background image. Then we just need to make sure that this window is positioned behind the main form. Yes, this is not such easy, but here is a library which makes the task really simple. Thanks to Anthony Mushrow for the idea and implementation: