Groups | Blog | Home
all groups > dotnet drawing api > march 2007 >

dotnet drawing api : Create a semi-trasparent layer


Paolo Niccolò Giubelli [Axettone]
3/8/2007 4:29:33 AM
Hi guys! Is it possible to create a transparent layer where I can write some
text? This layer should be visible even when I run an image viewer in
fullscreen mode.
Oliver Sturm
3/8/2007 3:36:35 PM
Hello Paolo,

[quoted text, click to view]

One approach to doing this would probably be to create a transparent
window that stays on top of everything else, so you could write something
on it. But that has a number of grave disadvantages - it's hard to do (and
it may not work at all with that full-screen image viewer, for instance if
that uses DirectX) and it prevents user interaction with the windows that
are below your window. Maybe it would be possible to create a
"pass-through" window that sends all Windows messages on to what lies
underneath... haven't tried it.

Another idea would be to draw into the root window directly, but then you
may end up having all kinds of redraw problems. I'm not aware of an API in
Windows that would let you do exactly what you want... maybe there's
something among the accessibility APIs? Or the new DWM stuff in Vista?


Oliver Sturm
--
Bob Powell [MVP]
3/8/2007 7:59:39 PM
If you're talking about an OSD (On Screen Display) type window such as
that used by some volume controls then the _correct_ technique is to
implement a window using the LayeredWindow API via interop. The
advantage of this is that your LayeredWindow implementation can use a
per-pixel alpha scheme that makes the edges of text less harsh and
aliased. If this isn't a big issue however, you can also get away with
using a window whose region is defined by the glyphs of the type face.

Beware however when using this method because there seems to be a bug in
the GDI+ text system that causes the glyphs from a True Type typeface to
have a different size to the bitmap drawn from them. This is not the
usual grid-fitting problem but a more serious on where the height of
glyphs seems to be incorrectly reported to the GraphicsPath object. This
will result in wild mismatches between regions and brushes when using
certain fonts.

(Thinking on it it's probably a case of near-enough-is-good-enough on
the part of the font designer. TT is a broad church)

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button