0

I'm trying to create a splash screen in C# WinForms (not WPF) with a semi-transparent image (32 bit PNG). However, I can't get it to show up properly.

This is the image I am working with (transparency checkerboard just for clarification):

enter image description here

Solutions I tried:

1: Using TransparencyKey:

This gave an undesired result since the picture also uses partially transparent areas.

enter image description here

2: Overriding OnPaintBackground:

bool painted = false;

protected override void OnPaintBackground(PaintEventArgs e)
{
    if (painted) return;
    e.Graphics.DrawImage(BackgroundImage, new Point(0, 0));
    painted = true;
}

The usage of the above code (found here) yielded another undesired result as the background was simply black.

enter image description here

Conclusion:

Is there any way to create such a splash screen inside of WinForms?

Jonas Kohl
  • 1,018
  • 1
  • 11
  • 28
  • Winforms does not make this render mode available out of the box, it is not compatible with a lot of controls in the toolbox. Doesn't matter for a splash screen when you only display a bitmap. Google "windows forms per-pixel alpha transparency" to find the code you need. – Hans Passant Aug 18 '18 at 13:07
  • **Or make a WPF splash screen in your WinForms application.** If you don't have to support very obsolete frameworks/OS, this might be the best solution. And if you still have to support those, then you might have an alternate simpler splash on those. – Phil1970 Aug 18 '18 at 14:09
  • If you use solution 1, then you might carefully select key color so that you semi transparent area in your picture are mixed with black, gray or white instead of cyan, magenta or other weird color. Or it could be a color in your image but just darker, lighter or a just enough different to the color in the image itself. Thus, if you want to use "compromise" solution like those you tried, then you typically have to adjust your image so that it works relatively well on typical background. – Phil1970 Aug 18 '18 at 14:17
  • What is your minimum OS requirement and which version of the framework are you targeting? – Phil1970 Aug 18 '18 at 14:19
  • @Phil1970 First of all, transparency key would not work at all because I have semi-transparent areas in my image. The minimum OS I'd like to support would be Windows 7. – Jonas Kohl Aug 18 '18 at 14:44
  • [Windows Forms Transparent Background Image](https://stackoverflow.com/a/33531201/3110834). – Reza Aghaei Dec 02 '19 at 05:49

0 Answers0