6

How can we show startup picture when my application starts as every software hows like Photoshop ,vs word etc?? I planed to paste it on form and then show it but there is top blue bar coming that has controls etc any idea/

Afnan Bashir
  • 7,319
  • 20
  • 76
  • 138
  • 1
    Don't forget to include an option into your program to turn the start up screen off, your users will love you for it! – Richard Lucas Dec 06 '10 at 09:39
  • Just don't make your splash screen top-most. I hate apps that I can't tab away from as they insist their splash screen remain visible until the app finally loads. – John Warlow Dec 06 '10 at 10:12

4 Answers4

9

If you're looking for the simplest way, you can use the .NET Framework's excellent built-in support for splash screens. You'll have to put aside any irrational fears that you might have of including something with the name "Visual Basic" in a C# application, but this way will save you from having to roll your own custom solution and worry about things like multi-threading, invoking, and all that. It all compiles down to the same IL in the end anyway. Here's how it works:

  1. Add a reference to Microsoft.VisualBasic to your project.

  2. Add a new form (named something like SplashForm) to serve as your splash screen.

  3. To make it look more like a proper splash screen, set the form's FormBorderStyle property to "None" and its StartPosition property to "CenterScreen". You can add any controls or images to this form that you want to be displayed on the splash screen to this form.

  4. Add the following code to your Project.cs file:

    using System;
    using System.Windows.Forms;
    using Microsoft.VisualBasic.ApplicationServices;
    
    namespace WindowsFormsApplication1
    {
       static class Program
       {
          [STAThread]
          static void Main(string[] args)
          {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             new SplashScreenApp().Run(args);
          }
       }
    
       public class SplashScreenApp : WindowsFormsApplicationBase
       {
          protected override void OnCreateSplashScreen()
          {
             this.SplashScreen = new SplashForm();
             this.SplashScreen.ShowInTaskbar = false;
             this.SplashScreen.Cursor = Cursors.AppStarting;
          }
    
             protected override void OnCreateMainForm()
             {
                 //Perform any tasks you want before your application starts
    
                 //FOR TESTING PURPOSES ONLY (remove once you've added your code)
                 System.Threading.Thread.Sleep(2000);
    
                //Set the main form to a new instance of your form
                //(this will automatically close the splash screen)
                this.MainForm = new Form1();
              }
           }
        }
    

If you want to do something fancy like create a transparent splash screen in the style of Adobe Photoshop, you can add an alpha-channel PNG image to your project's Resources file, and then add the following code to your splash screen form, replacing splashImage with the path to your embedded image resource:

protected override void OnPaintBackground(PaintEventArgs pevent)
{
    Graphics g = pevent.Graphics;
    g.DrawImage(splashImage, new Rectangle(0, 0, this.Width, this.Height));
}

protected override void OnPaint(PaintEventArgs e)
{
    //Do nothing here
}

For this to work, make sure that you have double buffering turned off, or else you'll get a black background to your form. There's really no reason to double buffer a splash screen anyway.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Why would you have to use Visual Basic for this? All your code seems like C#. – comecme Mar 07 '11 at 14:28
  • 2
    @comcme: I didn't suggest using Visual Basic, the code is indeed written in C#. I did, however, suggest adding a reference to `Microsoft.VisualBasic`, which has the words "Visual Basic" in it. All of the functions in that namespace are *also* written in C#, and as I mentioned, it all compiles down to the same IL anyway. The point is, the `WindowsFormsApplicationBase` class provided in that namespace already gives you all of the splash screen business for free, saving you from writing a bunch of additional code. It was just a joke that C# devs shouldn't freak out over the name. – Cody Gray - on strike Mar 07 '11 at 14:30
  • 2
    +1 Cody, you are the MAN! This is perfect. Why MS doesn't add support in winforms for the SplashScreen class, I don't know. But this is perfect. I tip my hat to you – Byron Whitlock Jun 16 '11 at 17:38
  • @Byron: They did. It's in the `Microsoft.VisualBasic` namespace. I mean, that's what I explained here, right? What else would you want them to do? Other than not bury the convenient stuff someplace where the very mention of the name makes most C# programmers' knees tremble. – Cody Gray - on strike Jun 17 '11 at 06:26
  • @CodyGray : How do i access a label control in my splashform inside the OnCreateMainForm method to show the use what is being loaded currently in the background – Shyju Mar 13 '12 at 14:52
  • @Shy: Look for the "Ask Question" button. – Cody Gray - on strike Mar 14 '12 at 04:32
2

You can remove all those blue bars etc, via this.FormBorderStyle = FormBorderStyle.None in your Form_Load().

So if I were you, I'd create a Form of specific Size, then set the following in Form_Load() or directly in the code generated by the designer:

this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPostition.CenterScreen;

Now you have a splash screen like many other apps - all you have to still do is write the code for all the making it visible or not stuff etc :)

aksu
  • 5,221
  • 5
  • 24
  • 39
Lorenz
  • 129
  • 1
  • 3
  • 9
1

WPF 3.5 and above actually has built in splash screen support, for faster rendering of the splash screen and much (much) less faffing with code. See this page for details.

Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
0

Are you writing a WinForms or a WPF application? You will have to set different properties depending on which kind you write. If you are writing a WPF application, you can add the WindowStyle="None" and ResizeMode="NoResize" attributes to the Window top-level element in XAML. The first one will remove the title bar with the minimize, resize, and close buttons whereas the second one will remove the border around the form.

Now, you have a borderless form that you can modify to create a splash screen if you want or to simply add your startup image. If you don't want your default form to appear, you need to add Background="Transparent" and AllowsTransparency="True" attributes as well. The first one will set the background color to transparent whereas the second one allows your program to look transparent. Now, you can add any image in any shape, and the user will see only that image at program startup.

P.S. Make sure to load another form once the startup screen has been shown for a set amount of time or once the methods that are supposed to "load" stuff return control.

Pretty simple stuff!!

user1234567
  • 603
  • 1
  • 4
  • 10