개발/C# .NET

C# - Splash Screen 만들기

xwing 2010. 8. 16. 00:00
갑자기 생각나서 간단히 구현해 봤습니다.

스플래시 윈도우에선 아무것도 수행안하고 그냥 메세지만..
보통은 필요한 데이터를 로딩한다던가, 어디다(?) 연결작업을 수행한다던가 머 그렇지요.. 아님 로고를 보여준다던가..

우선 윈폼 프로젝트를 하나 생성하고요..

윈도우를 두개 만듭니다.
1. 메인 윈도우
2. Splash 윈도우

메인 윈도우가 나타나기 전에 Splash 윈도우를 먼저 띄우고 필요한 처리가 다 되면 Splash 윈도우를 닫고
메인 윈도우를 나타내게 됩니다.

소스는 머 대충 아래와 같이 

program.cs

    1 static class Program

    2 {

    3         delegate void SampleDelegate();

    4 

    5 

    6         /// <summary>

    7         /// 해당 응용 프로그램의 주 진입점입니다.

    8         /// </summary>

    9         [STAThread]

   10         static void Main()

   11         {

   12 

   13             Application.EnableVisualStyles();

   14             Application.SetCompatibleTextRenderingDefault(false);

   15 

   16             SplashForm splashScreen = new SplashForm();

   17             Application.Run(splashScreen);  // Splash window 띄우기

   18 

   19             Application.Run(new Form1());   // 메인 윈도우 띄우기

   20         }

   21 

   22 }


SplashForm.cs

    1 public partial class SplashForm : Form

    2 {

    3         delegate void TestDelegate(string msg);

    4         delegate void TestDelegate2();

    5 

    6         public SplashForm()

    7         {

    8             InitializeComponent();

    9 

   10             System.Threading.Thread thread = new System.Threading.Thread(Thread1);

   11             thread.Start();

   12         }

   13 

   14         private void showText(string msg)

   15         {

   16             lblCount.Text = msg;

   17         }

   18 

   19         private void formClose()

   20         {

   21             this.Close();

   22         }

   23 

   24         private void Thread1()

   25         {

   26             for(int i=100; i > 0; i--)

   27             {

   28                 this.Invoke(new TestDelegate(showText), i.ToString());

   29                 System.Threading.Thread.Sleep(100);

   30             }

   31 

   32             this.Invoke(new TestDelegate2(formClose));

   33         }

   34 }


splash윈도우 화면엔 라벨을 하나 만들고 100 부터 0까지 숫자를 찍어댓다.

이렇게 간다히 Splash화면을 하나 심심풀이로 만들어 봤다.