C# - Transparent Form

user525192 picture user525192 · Nov 30, 2010 · Viewed 41k times · Source

I currently have a Form with all the desired effects except one. The current form consists out of a menustrip at the top with a panel underneath which contains labels and pictureboxes. When the form is launched the menustrip is not visible, it only becomes visible while the user presses the 'Alt'-button and disappears in the same manner.

The panel will have a background-image with a transparent background (.PNG). This image will become the main layout of the form as I set the borderstyle to none. Now the problem is that the form still has the white/grayish background underneath the panel.

Now my question is how do I make the form transparent so the image on the panel becomes the main layout rather than just the image with the forms backcolor underneath it. I do not want to use the Opacity property as I want the panel to be visible 100%.

Answer

Øyvind Bråthen picture Øyvind Bråthen · Nov 30, 2010

Assuming WinForms.

You can do this, but you cannot make the edges semi-transparent.

Try this.

On the form, set the following properties:

BackColor = Color.Lime;
TransparencyKey = Color.Lime;

This will make the form transparent. Then set the backgroundimage:

BackgroundImage = myImage:

The parts of the backgroundimage that is also Color.Limewill also get transparent.

If you also want to get rid of the Forms borders, add this line as well:

FormBorderStyle = FormBorderStyle.None;