1

[UPDATE] I've used the example and link in the comment by Hans Passant and it's working great. Thanks for the help everyone, I'm not sure how to select an answer when it's a comment so I'll include this update at the top for future viewers.

So I'm trying to get my splash screen to display in my winforms application while an excel instance loads in the background and also to allow the company logo and contact information to be displayed.

I'm new to winforms, but from tutorials on the internet, I've found that you can create an "empty" form and change to UI to a borderless form with your splash as the BackgroundImage property. I have done that with a .bmp file and am displaying it with this code.

    private void Form1_Load(object sender, EventArgs e)
    {
        SplashScreen splash = new SplashScreen(); 
        var start = DateTime.Now;

        splash.Show();
        xlHelper = new ExcelHelper();
        var end = DateTime.Now;

        Thread.Sleep(3000 - ((start - end).Milliseconds));
        splash.Close();           
    } 

This seems to work fine on my Windows 8 machine, and another Windows 7 machine however on XP (SP3) it does not display, nothing does.

Below, I have changed the display properties on it and included FixedSingle FormBorderStyle instead of None, and it's displaying what's below. So it's loading the splash screen but cannot display the background. Does anyone have any insight into this? Thanks.

Empty Splash Screen

Josh
  • 2,767
  • 1
  • 27
  • 31
  • Does it work (as a test), if you comment out the code for `ExcelHelper`? – WiredPrairie Nov 10 '13 at 19:13
  • 2
    Yeah, that's not going to work, that's just not the way splash screens work, do consider using the [built-in support](http://stackoverflow.com/a/393870/17034) in .NET. You can limp along by adding `splash.Update();` after the Show() call. – Hans Passant Nov 10 '13 at 19:47

1 Answers1

0

Here is one way to do it.

[Program.cs]
static class Program
{
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
           var formMain = new Forms.FormMain();
           var splash = new Forms.FormSplash( formMain );
           splash.Show();
           Application.DoEvents();
           Application.Run( formMain );
        }
}

[FormMain.cs]
public partial class FormMain : Form
{
        public FormMain()
        {
            // This Form is initially invisible.
            // The splash screen Form is responsible to making this form visible.
            //
            this.Opacity = 0;

            InitializeComponent();
        }
}

[FormSplash.cs]
    public partial class FormSplash : Form
    {
        Forms.FormMain _theMainForm;

        public FormSplash()
        {
            InitializeComponent();

            // ctlLogoText is a RichTextBox control.
            //

            this.ctlLogoText.BorderStyle = BorderStyle.None;
            this.ctlLogoText.Rtf = SR.LogoText;
        }

        public FormSplash( Forms.FormMain theMainForm )
            : this()
        {
            _theMainForm = theMainForm;

            Application.Idle += new EventHandler( Application_Idle );
        }

        void Application_Idle( object sender, EventArgs e )
        {
            Application.Idle -= new EventHandler( Application_Idle );

            if ( null != _theMainForm )
            {
                // theTimer is a System.Windows.Forms.Timer.
                //
                this.theTimer.Interval = Math.Min( 5000, Math.Max( 1000, 1000 * Settings.Default.SplashDelay ) );
                this.theTimer.Start();
            }
        }

        void theTimer_Tick( object sender, EventArgs e )
        {
            this.theTimer.Stop();
            this.Close();

            Application.DoEvents();

            _theMainForm.Opacity = 100;
            _theMainForm.Refresh();
            _theMainForm = null;
        }
    }
ahazzah
  • 756
  • 1
  • 7
  • 18