c\#간단 한 시작 화면 만 드 는 방법

3107 단어 c#시동 화면
본 논문 의 사례 는 c\#간단 한 시작 화면 을 만 드 는 방법 을 서술 하 였 다.모두 에 게 참고 하도록 공유 하 다.구체 적 인 분석 은 다음 과 같다.
시작 화면 은 프로그램 이 구성 요 소 를 불 러 올 때 사용자 가 조금 만 기다 릴 수 있 도록 하 는 알림 상자 입 니 다.좋 은 소프트웨어 는 시작 대기 수요 가 있 을 때 반드시 시작 화면 을 만들어 야 한다.시작 화면 은 사용자 로 하여 금 프로그램 로드 의 느 린 준 비 를 하 게 하고 로 딩 의 진도 와 내용 을 알 게 할 수 있다.본문 은 단지 기록 의 가장 간단 한 구조 일 뿐이다.
VS 2010 은 C\#Windows 창 프로그램 을 만 들 고 메 인 창 을 FormMain 으로 바 꾸 고 SplashScreen 이라는 창 을 만 듭 니 다.프로그램 에 시작 화면 으로 그림 을 불 러 옵 니 다.다음 그림 입 니 다.

그리고 SplashScreen.cs 코드 편집

/// <summary> 
///      
/// </summary> 
public partial class SplashScreen : Form 
{ 
 /// <summary> 
 ///        
 /// </summary> 
 static SplashScreen instance; 
 /// <summary> 
 ///       
 /// </summary> 
 Bitmap bitmap; 
 public static SplashScreen Instance 
 { 
  get 
  { 
   return instance; 
  } 
  set 
  { 
   instance = value; 
  } 
 } 
 public SplashScreen() 
 { 
  InitializeComponent(); 
  //         
  const string showInfo = "    :           ,   ...";
  FormBorderStyle = FormBorderStyle.None; 
  StartPosition = FormStartPosition.CenterScreen; 
  ShowInTaskbar = false; 
  bitmap = new Bitmap(Properties.Resources.SplashScreen); 
  ClientSize = bitmap.Size; 
  using (Font font = new Font("Consoles", 10)) 
  { 
   using (Graphics g = Graphics.FromImage(bitmap))
   { 
    g.DrawString(showInfo, font, Brushes.White, 130, 100);
   } 
  } 
  BackgroundImage = bitmap; 
 } 
 protected override void Dispose(bool disposing)
 {
  if (disposing && (components != null)) 
  { 
   if (bitmap != null) 
   { 
    bitmap.Dispose(); 
    bitmap = null; 
   } 
   components.Dispose(); 
  } 
  base.Dispose(disposing); 
 } 
 public static void ShowSplashScreen()
 { 
  instance = new SplashScreen();
  instance.Show(); 
 } 
}
그리고 메 인 프로그램 이 시 작 될 때 호출 합 니 다.

static class Program 
{ 
 /// <summary> 
 ///          。 
 /// </summary> 
 [STAThread] 
 static void Main() 
 { 
  Application.EnableVisualStyles(); 
  Application.SetCompatibleTextRenderingDefault(false);
  //    
  SplashScreen.ShowSplashScreen(); 
  //        :    ,       
  //           
  System.Threading.Thread.Sleep(3000); 
  //    
  if (SplashScreen.Instance != null) 
  { 
   SplashScreen.Instance.BeginInvoke(new MethodInvoker(SplashScreen.Instance.Dispose));
   SplashScreen.Instance = null; 
  } 
  Application.Run(new FormMain()); 
 } 
}
효 과 는 다음 그림 과 같다.

본 고 에서 말 한 것 이 여러분 의 C\#프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기