For the current project at SKOV, I was in need of a tooltip window that can show a lot of textual information.
Apart from this requirement, the tooltip should support
a gradient background, have round borders, be semi transparent and cast a soft shadow. To achieve this, one must use alpha blending to "softly" blend the border, the shadow and the transparency to the underlying surface.
WinForms have by default support for alpha blending on a drawing surface, e.g. a Form, so drawing a semi transparent gradient tooltip that casts a soft shadow is no problem. However, blending the tooltip on top of another window, such as the desktop or an underlying Window is rather troublesome, as WinForms apparently has no direct support for this. Instead one must rely on native Win32 to achieve this, using layered windows which were introduced in Windows 2000, as described in this MSDN post: http://msdn.microsoft.com/en-us/library/ms997507.aspx.
I have implemented the stuff described in the MSDN post, and made a quick test application showing the effect. The tooltip is drawn as a rectangle with round corners with a 2 pixel border. A soft shadow is also drawn.

The procedure (simplified) is as follows:
- Apply the WS_EX_LAYERED style to the Window, to make it a Layered Window.
- Create a 32bit Argb bitmap which encompasses the whole Window including shadow.
- Set the alpha value of the border and background colors to the desired opacity value.
- Draw the shadow, background and border to to the bitmap.
- Draw the content, e.g. text showing the mouse position.
- Create a compatible device context (DC) and copy the bitmap to it.
- Call UpdateLayeredWindow with the DC, blending mode, etc. as arguments.
I have included a demo project, with C# code, showing the tooltip in action. Anyone is free to use the code as they see fit.
The demo project can be downloaded from here: APrettyTooltip 1.0.zip (43.11 kb)
Enjoy!
Programming in General
WinForms, .NET, C#, Tooltip, Opacity, Transparent, Layered, Layered Window, Win32, Show