2

I'm trying to make a Splash Screen 4 an Win application.

my setup:

form border style is set to none. start position is screen center. background image of the form is set to a PNG file, with rounded edges and a "build in" drop shadow.

In code I've set:

this.SetStyle( ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle( ControlStyles.UserPaint, true);
this.SetStyle( ControlStyles.DoubleBuffer, true);
this.SetStyle( ControlStyles.SupportsTransparentBackColor, true);

this.AllowTransparency = true;
this.BackColor = Color.Transparent;

but when i test, it says that the form can't have a transparent background color.

i DO NOT want to set a transparency key, cuz it causes trouble with the dropschadow ( semi transparent part of the png )

also i dont want to set opacity to 0%, cuz it also effects my PNG.

in fact i just want ONLY my png shown as the window. additionaly there will be some dynamic text on top of it and a process bar in the future...

Any ideas? how to tell the form that is CAN have transparent background like the splash screen of ADOBE PHOTOSHOP CS5

svick
  • 236,525
  • 50
  • 385
  • 514
Ace
  • 1,437
  • 6
  • 28
  • 46
  • What you're asking for isn't available in the default form you click by Project -> Add -> New Form. What you have to do, is extend the default functionality. You've already got some headstart there in the code you posted - this is what you would add to your extended form class (or some modified version of it). Other things you would add are custom regions, to define your form shape. Forgot how to do transparency. Coming up with some resource links. – Jason Mar 12 '12 at 12:25
  • Resource links: http://stackoverflow.com/questions/5092216/c-sharp-form-with-custom-border-and-rounded-edges and http://stackoverflow.com/questions/1592876/c-sharp-make-a-borderless-form-movable. Not sure about your transparency though, since you don't want to use a Transparency Key. – Jason Mar 12 '12 at 12:27
  • 1
    Honestly, to avoid the potential hassle and complexity of alternate methods to using transparency keys, you might as well edit out the border of your PNG (just erasing those pixels on Microsoft Paint, or magic-wand selecting the rest of your splash screen in Photoshop, inverting the selection and deleting the border) and re-draw it yourself. – Jason Mar 12 '12 at 12:29
  • well first of all, i'm almost new to c#, so i dont get the idea X__X i don't understand what u mean with editing the png. splashscreen.png -> http://acid.chdustar.com/mpx2%20splash.png and what u mean with extended form class ? – Ace Mar 12 '12 at 13:02
  • i have no idea where to begin. isn't there any method to hide the window but leave the png as a child of any wrapper or such? i've also seen a method called splash() or something like that... but i can't really remember. do u have any resources or code to deal with ? i've googled for hours , but i couldn't find alything that is helpful to me. – Ace Mar 12 '12 at 13:02
  • so frustrading. i thought of making the splash screen in flash as an air application where u can just say that the window is transparend and has no border. and manually start that air-splashscreen inside the mein app. but i think that would be much too dirty. want some clean solution X__X anyways thx 4 your idea, i'll try to understand the codes in that links. – Ace Mar 12 '12 at 13:02
  • You could use WPF. WPF makes it so ridiculously easy to make transparent-background windows. – Kendall Frey Mar 12 '12 at 13:04
  • Might be a bit difficult if you're not familiar with C#. Definitely read up on examples in codeproject. – Jason Mar 12 '12 at 13:05
  • well i mean, i am familiar with c++... so , there is not MUCH difference ;) what is WPF ? do u have any links 4 a guy like me who is too stupid to google it XD – Ace Mar 12 '12 at 13:07
  • i found something on youtube... http://www.youtube.com/watch?v=T_RLyi-YMqI I'll give it a try , if it works, well, congratulation @Kendall :D thx 4 all your replys – Ace Mar 12 '12 at 13:09
  • WPF is the newest UI technology for .NET. http://msdn.microsoft.com/en-us/library/ms754130.aspx I estimate that it would take 5-10 lines of code to solve your problem using XAML. (XAML is a UI design language, very similar to XML syntax.) – Kendall Frey Mar 12 '12 at 13:11

2 Answers2

3

I spent a few hours looking for a way to do this in Win Forms as well so I thought I would share my solution.

My splash screen image is a .png with a transparent background and various shadows that extend over the transparent background. Using uncommon colors as the background of the control along with a transparency key left ugly patches underneath the semi-transparent shadows.

I was able to get the desired result by setting the background image of the form to the image I wanted to display and overriding the OnPaintBackground function like so:

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

I'm only bumping this old thread because it's the top Google result for a few different keyword combos that I tried.

See also Transparent Splash Screen which is where I found this solution from another SO post.

Dylan Musil
  • 319
  • 1
  • 13
  • I tried this but its painting image very large as compared... the image placement is also misplaced like i have it to stretch but still its showing the other way. Also i m not able to set the transparent color either. – KMX Jun 22 '16 at 00:16
  • You would probably need to resize the image. I set the ClientSize of the form to be the same size as the image. The only control on the form was a PictureBox containing the image. – Dylan Musil Jul 22 '16 at 14:53
  • Doesn't _really_ work though because the behind image doesn't change. it's similar to the 'grab a bitmap of background' answer. – n00dles Jul 24 '17 at 01:55
0

Here is a simple example of a WPF splash screen. This is all in XAML. I didn't write a line of C# to make it work.

<Window x:Class="WpfSplashScreen.SplashScreen"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None" Background="Transparent" AllowsTransparency="True"
        ShowInTaskbar="False" SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterScreen">
    <Image Source="logo.png" Stretch="None" />
</Window>

This is just an example, and would need some more code to make it useful, but that is how easy a splash screen is in WPF.

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
  • thx 4 ur code, i already started my splashscreen project, it looks almost similar to ur example, but as u said, much complicated ;) anyways thx, WPF is my solution, i'm glad that i know WPF now. ^^ – Ace Mar 12 '12 at 13:50