I am trying to design a semi transparent screen as Adobe Photoshop’s and visual studios semi transparent welcome splash screen while opening the Application. I set FormBorderStyle to none, And I place a picturebox on it and I added a png image to it, I Set picturebox color to transparent, But I am not able to set Form’s back color as transparent. Below are exmples:
and when I set form’s Back Color as transparent, it shows me error
Property Not Valid. Control does not support transparent background colors.
I already tried couple of code samples as shown below:
public Splash_Screen()
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
this.BackColor = Color.Red;
BackColor = Color.Transparent;
}
and
public Splash_Screen()
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
}
But nothings works for me.. Any suggestions?
2
Answers
You set your semi transparent background image to
BackgroundImage
property of the form. Then set aBackColor
to your form, and set theTransparencyKey
property of the form to the same color you set for your formsBackColor
. Then remove the borders of the form by changingFormBorderStyle
property of the form toNone
. That will do it.This question is old, but I decided to chime in because it’s the first result for “transparent splash screen C#”, and Tolga’s solution can produce strange borders with the color of the
TransparencyKey
around some edges of the image. This is more evident if it has lines anti-aliased with semitransparent pixels.I copied this code from here. Unfortunately, neither I nor the poster know the original author.
I’ve also made some modifications to support changing the form’s opacity.
Splash.cs:
APIHelp.cs: