Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2005

Tip: Looking for answers? Try searching our database.

SplashScreen implementation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RYoung - 24 Oct 2005 14:33 GMT
Hello all,

I've got a need to display a splash screen while the main form loads. The
main form will be doing some initialization and posting messages to the
splash screen for display. Here is what I have in a nutshell (irrelevant
methods omitted):

public class SplashScreeen : Form
{
   private delegate void DisplayStatusDelegate( string msg );

   public void DisplayStatus( string msg )
   {
       if ( label1.InvokeRequired )
       {
           label1.BeginInvoke( new DisplayStatusDelegate( DisplayStatus ),
new object[]{ msg } );
       }
       else
       {
           label1.Text = msg;
       }
   }

   public void ShowSplash()
   {
           this.ShowDialog();
   }
}

// MainForm.TopMost = true
public class MainForm : Form
{
      private void MainForm_Load( ... )
      {
           SplashScreen splash = new SplashScreen();
           Thread splashThread = new Thread( new ThreadStart(
splash.ShowSplash ) );
           splashThread.Start();

           splash.DisplayStatus( "Initializing" );
           Thread.Sleep( 1000 );
           splash.DisplayStatus( "Sleeping" );
           Thread.Sleep( 2000 );
           splash.DisplayStatus( "Finished" );
           Thread.Sleep( 1000 );

           splash.Close();
           splashThread.Abort();

           Activate();
       }
}

Everything works as expected. The Thread.Sleep calls will be replaced with
intialization routines for the app.
Any comments as to what could be wrong with this implementation is
appreciated.

Ron


Colin Neller - 25 Oct 2005 19:01 GMT
A couple of things: Thread "A" creates the form and closes it, but
thread "B" calls ShowDialog.  All of these things should be on the same
thread.  Your implementation of DisplayStatus looks good, though.

You might take a look at this splash screen example:
http://www.codeproject.com/csharp/PrettyGoodSplashScreen.asp.  Look at
the comments at the bottom of the page if you have trouble with focus.

Hope that helps,
Colin Neller
http://colinneller.com/

> Hello all,
>
[quoted text clipped - 56 lines]
>
> Ron
RYoung - 26 Oct 2005 10:51 GMT
Interesting...Thanks for the reply and link :) Will have a look.

Ron

>A couple of things: Thread "A" creates the form and closes it, but
> thread "B" calls ShowDialog.  All of these things should be on the same
[quoted text clipped - 70 lines]
>>
>> Ron

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.