Monday, January 28, 2008

Build transparent windows form using C#

Developing a transparent windows form in Visual Studio 2005 using C# is not that big deal! By just setting a few properties, you can design a windows form you can look through. This article elaborates the process of converting a windows form into a transparent form using C#.

Create Visual Studio 2005 project using C# as a language of choice. In the picture of the transparent form I'm about to show you, I just made it borderless by settings its FormBorderStyle property to None. It is just to make it look interesting, otherwise it has nothing to do with the actual process of making it transparent.

To make the windows form look transparent just set its BackColor property to whatever color you like (or the color you don't like...because this color will not be visible due to transparency :) ). I set it to MediumSlateBlue. The second most important property which you need to set to achieve the objective of form transparency is Transparencykey. The important point to note here is that the color should be same in TransparencyKey and Form's BackColor. So, I'll set the TransparencyKey value to MediumSlateBlue.


It looks like a broken form, but actually its not! It is a transparent windows form shown on my computer's desktop. The bars at the top and left (if you can see that as well :) ) are the labels with some other background color. And there are two text boxes and one close button on the form that are viewable and working, while you can see through the form.



No comments: