Welcome to MSDN Blogs Sign in | Join | Help

Transparent Window Sample

There's been some internal discussion about transparent and/or non-rectangular windows recently, and Nick Kramer recently addressed the issue in a blog post. Although I haven't had time to build a new solution that works with Avalon, I do have some older code that I've used to create layered windows in the past. Feel free to download the C# AlphaWindow solution for Visual Studio 2005 (the code originated in Visual Studio 2003). I don't know if this is the absolute best way to accomplish this, but it's worked for me in practice.

Basically, you have to provide a 32-bit image that includes an alpha channel (PNG). In the case of this example, the image is included as an embedded resource in the Visual Studio project. A quick look at the code should get you going. Notice that you can drag the window by clicking on any portion of the image that isn't completely transparent, including the drop shadow.

These windows work great for application splash screens where you display the window, do some start-up work, and hide it when you're done. You can also easily imagine Konfabulator-like functionality. I'd love to see someone adapt this to an Avalon sample. If you do this, share it with the rest of us in the Channel 9 Sandbox. Good luck!

Published Thursday, July 07, 2005 2:32 PM by mswanson
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Transparent Window Sample

There was cool "Per-pixel Alpha Blend" sample at CodeProject about a year ago. It uses same technic.

And about a month ago I written application for my job, that works like semi-transparent "glass" whiteboard on the top of other window. When you draw on it by mouse, it fills the path by pen. This is done using CodeProject sample technics you use to.

So I can report: it works for slow animations well. You shown static picture, but it works for dynamics too.

If you are interesting, I can send the sample to you. See my email.

However, to implement Avalon on top of such windows, it should be much more hard work. There is a way to render Visual(s) to bitmap in Avalon.

So it can be built some kind of 'host' component that dispatches events to Visual and eventually renders Visual to transparent bitmap and then to layered window. And I believe it can be done even outside of Avalon team. But the performance will be slow: rendering in bitmap fallbacks to software but not accelerator.

---
Oleg Mihailik, Developer Security MVP
Kyiv, Ukraine
Thursday, July 07, 2005 5:54 PM by mihailik

# re: Transparent Window Sample

I am hoping that Avalon provides much better support for this stuff than the current layered window approach, btw. Layered windows have great initial promise, but then you have to jump through so many hoops to get stuff to work. And there is no way to run video or a browser control (or even a rich text control) on them because you have to provide the image for the entire window. The only way to make stuff like that work is if you use nefarious methods which aren't 100% reliable. Speaking as a current Konfabulator developer and a former Apple employee who worked on the UI Toolbox for almost 8 years, I can tell you that a lot of work needs to happen (and the current set of very bad bugs that exist in gdi+ need to be fixed) in order to truly create a good, solid platform for this kind of thing.
Tuesday, July 12, 2005 1:11 PM by Ed Voas

# re: Transparent Window Sample

Can someone point me to a sample written in plain C?? i need this really hard by now ;o)

Thx in advance, Markus
Thursday, July 14, 2005 4:17 AM by Markus Duft

# re: Transparent Window Sample

Recently Carl Franklin (www.dotnetrocks.com) and I created an application that takes transparent windows to the extreme. Check it out at http://shrinkster.com/4x9 and http://shrinkster.com/6so

Particularly note the translucent (Longhorn Aero Glass style) windows at the second URL.
Wednesday, July 20, 2005 7:58 AM by Dax Pandhi

# re: Transparent Window Sample

Hi Michael i want to thank u for this helpfull code , but i still have a question this code didnt help me to design a similar form but containd controls

can u help me to naswer this

thx again for sharing ur efforts
Wednesday, June 14, 2006 5:30 AM by AMSS

# Visual Studio 2003

Hi Michael,

You said this project started in Visual Studio 2003.  I am having a rough time trying to set the build action to a item as a embedded resource in visual studio 2003.  Do you still have the project in 2003, or could you explain to me how to set a item as a embedded resource in visual studio 2003.  Thanks a whole lot for this project.
Tuesday, September 19, 2006 8:59 AM by Philip

# re: Transparent Window Sample

Michael, I was not able to host controls on this window. Controls do not show up. Any idea why?

Thursday, December 14, 2006 1:10 AM by Agnel

# re: Transparent Window Sample

i want this sample but in visual basic .net 2005 not in c# can u help me

Thursday, May 17, 2007 1:48 AM by samah

# re: Transparent Window Sample

Is there any way to put controls on the form??

Monday, October 01, 2007 11:30 AM by julek

# re: Transparent Window Sample

Hello. I'am very interested in this.

Is there any way to put controls on the form??

Tuesday, October 02, 2007 2:23 AM by Frank

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker