I wanted to make my windows form transparent so removed the borders, controls and everything leaving only the forms box, then I tried to the BackColor and TransparencyKey to
What works for me is using a specific color instead of the real ability of .png to represent transparency.
So, what you can do is take your background image, and paint the transparent area with a specific color (Magenta always seemed appropriate to me...).
Set the image as the Form's BackgrounImage
property, and set the color as the Form's TransparencyKey
. No need for changes in the Control's style, and no need for BackColor.
I've tryed it right now and it worked for me...
Here was my solution:
In the constructors add these two lines:
this.BackColor = Color.LimeGreen;
this.TransparencyKey = Color.LimeGreen;
In your form, add this method:
protected override void OnPaintBackground(PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.LimeGreen, e.ClipRectangle);
}
Be warned, not only is this form fully transparent inside the frame, but you can also click through it. However, it might be cool to draw an image onto it and make the form able to be dragged everywhere to create a custom shaped form.
I tried almost all of this. but still couldn't work. Finally I found it was because of 24bitmap problems. If you tried some bitmap which less than 24bit. Most of those above methods should work.
Should it have anything to do with "opacity" of the form / its background ? Did you try opacity = 0
Also see if this CP article helps:
I've tried the solutions above (and also) many other solutions from other posts.
In my case, I did it with the following setup:
public partial class WaitingDialog : Form
{
public WaitingDialog()
{
InitializeComponent();
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
// Other stuff
}
protected override void OnPaintBackground(PaintEventArgs e) { /* Ignore */ }
}
As you can see, this is a mix of previously given answers.
I had drawn a splash screen (32bpp BGRA) with "transparent" background color in VS2013 and put a pictureBox in a form for display. For me a combination of above answers worked:
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = this.pictureBox1.BackColor;
this.TransparencyKey = this.pictureBox1.BackColor;
}
So make sure you use the same BackColor everywhere and set that color as the TransparencyKey.