2011-11-12 6 views
0

.Net에서 SplashScreen 클래스를 사용하여 응용 프로그램이로드되는 동안 동적 메시지를 표시 할 수 있습니까?SplashScreen 및 사용자 정의 메시지

같은 것.
로드 된 모듈 ...
로드 된 모듈 2 ...
등등.

답변

2

아니요,이 기능을 직접 코딩해야합니다. 내장 스플래시 화면에는 정적 이미지 만 표시 할 수 있습니다.

2

'System.Theading'을 사용하여이 작업을 수행 할 수 있습니다. 다음 코드는 별도의 스레드에서 "스플래시 화면"을 시작합니다. 응용 프로그램 (아래 예에서는 MainForm())이로드되거나 초기화됩니다. 첫째로 "main()"메쏘드 (program.cs 파일의 이름을 변경하지 않았다면)에서 스플래시 화면을 보여 주어야합니다. 이것은 시작할 때 사용자에게 보여주고 자하는 WinForm 또는 WPF 양식입니다. 귀하되는 SplashScreen 코드에서

[STAThread] 
    static void Main() 
    { 
     // Splash screen, which is terminated in MainForm.  
     SplashForm.ShowSplash(); 

     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 

     // Run UserCost. 
    Application.Run(new MainForm()); 
    } 

을 다음과 같이해야합니다 :

public partial class SplashForm : Form 
{ 

    // Thredding. 
    private static Thread _splashThread; 
    private static SplashForm _splashForm;  

    public SplashForm() 
    { 
     InitializeComponent(); 
    } 

    // Show the Splash Screen (Loading...)  
    public static void ShowSplash()  
    {   
     if (_splashThread == null)   
     {    
      // show the form in a new thread    
      _splashThread = new Thread(new ThreadStart(DoShowSplash));    
      _splashThread.IsBackground = true;    
      _splashThread.Start();   
     }  
    }  

    // Called by the thread  
    private static void DoShowSplash()  
    {   
     if (_splashForm == null)    
      _splashForm = new SplashForm();   
     // create a new message pump on this thread (started from ShowSplash)   
     Application.Run(_splashForm); 
    }  

    // Close the splash (Loading...) screen  
    public static void CloseSplash()  
    {   
     // Need to call on the thread that launched this splash   
     if (_splashForm.InvokeRequired)    
      _splashForm.Invoke(new MethodInvoker(CloseSplash));   
     else    
      Application.ExitThread();  
    } 

} 

이 당신을 진행 할 수 있도록 별도의 백그라운드 스레드에서 스플래시 양식을 실행을이 다음과 같이) (주부터 시작이다 메인 애플리케이션의 렌더링. 로드에 관한 메시지를 표시하려면 기본 UI 스레드에서 정보를 가져 오거나 순수한 미적 속성으로 작업해야합니다. 마무리 및 응용 프로그램을 사용하면 기본 생성자 내에서 다음을 배치 초기화되었을 때 시작 화면을 닫으려면 (당신이 원한다면 당신은 생성자를 오버로드 할 수 있습니다) :

public MainForm() 
    { 
     // ready to go, now initialise main and close the splashForm. 
     InitializeComponent(); 
     SplashForm.CloseSplash(); 
    } 

위의 코드는 상대적으로 쉽게해야 따르다.

이 정보가 도움이되기를 바랍니다.

관련 문제