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!

Comments (11)

  1. mihailik says:

    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

  2. Ed Voas says:

    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.

  3. Markus Duft says:

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

    Thx in advance, Markus

  4. Dax Pandhi says:

    Recently Carl Franklin ( and I created an application that takes transparent windows to the extreme. Check it out at×9 and

    Particularly note the translucent (Longhorn Aero Glass style) windows at the second URL.

  5. AMSS says:

    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

  6. Philip says:

    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.

  7. Agnel says:

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

  8. samah says:

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

  9. julek says:

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

  10. Frank says:

    Hello. I’am very interested in this.

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

  11. Max says:

    You don’t put controls on these forms. You stack them under a main transparent form.

    Most of what I’ve seen is a mechanism where you use 2 forms:

    form 1: your layered window (under your main, borderless, window)

    form 2: your borderless form with your controls, and with a TransparencyKey set where ever you need it to show through.

    Take a look at how the Menu from WinXP are built with Spy++…… blows my mind that Microsoft put such a crappy design into production…. The context menu uses 3 windows: main one on which the menu items are, one to the right for the drop shadow, and one to the bottom for the drop shadow…

    Get the idea?

    Hope this helps.

Skip to main content