18

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%.

Rémi
  • 3,867
  • 5
  • 28
  • 44

2 Answers2

37

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;
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • This did the trick! Thank you for the swift reply and detailed explanation. I cannot believe it is this simple! Thanks again. –  Nov 30 '10 at 13:34
  • Glad I could be of help. I did the same thing once when I made a splash screen for an application. – Øyvind Bråthen Nov 30 '10 at 13:41
  • Thanks, it works well. One question, I notice that if I use drawstring to draw some text to a transparent label on a transparent form, there will be a lime(or any color used as TransparencyKey) jaggies around the text. Do you know how to solve it? – camino Apr 17 '19 at 14:43
4

Be careful when you will choosing backcolor. Chose a Backcolor to differ from your text, images, and any control's color that mean choose a color that you will never going to use in your Form and I think Fuchsia/ lime will be the best choice.For choosing a backcolor codes are below:

this.BackColor = Color.Fuchsia;

and then Make that color to Transparent by using that codes:

TransparencyKey = Color.Fuchsia;
  • 1
    Why chooose a color you will never going to use? – nalply Oct 10 '12 at 19:43
  • 6
    Because if you do use that color somewhere else, and you've set it to be the `TransparencyKey` then it will also be made transparent. Sort of like if the weather man wore a bright green suit in front of the green screen. – DTI-Matt Dec 05 '12 at 19:57
  • yup coz we are going transparent a color when you will use color which you use in form then that text or image will also be transparent – kislay kumar Dec 19 '12 at 10:05
  • you can do with form properties as well rather than code i guess. – Moxet Jan Jan 08 '14 at 10:10