Transparent background on winforms?
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.
The manner I have used before is to use a wild color (a color no one in their right mind would use) for the BackColor and then set the transparency key to that.
this.BackColor = Color.LimeGreen;
this.TransparencyKey = Color.LimeGreen;
A simple solution to get a transparent background in a windows form is to overwrite the OnPaintBackground
method like this:
protected override void OnPaintBackground(PaintEventArgs e)
{
//empty implementation
}
(Notice that the base.OnpaintBackground(e)
is removed from the function)
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.