国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c#制作簡單啟動畫面的方法

2020-01-24 01:53:39
字體:
供稿:網(wǎng)友

本文實(shí)例講述了c#制作簡單啟動畫面的方法。分享給大家供大家參考。具體分析如下:

啟動畫面是程序啟動加載組件時一個讓用戶稍微耐心等待的提示框。一個好的軟件在有啟動等待需求時必定做一個啟動畫面。啟動畫面可以讓用戶有心理準(zhǔn)備來接受程序加載的緩慢,還可以讓用戶知道加載的進(jìn)度和內(nèi)容。本文只是記錄最簡單的構(gòu)架。

VS2010創(chuàng)建一個C# Windows窗體應(yīng)用程序,將主窗體改名為FormMain,再創(chuàng)建一個窗體起名為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();   // 設(shè)置窗體的類型   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();  } }

然后在主程序啟動時調(diào)用

static class Program {  /// <summary>  /// 應(yīng)用程序的主入口點(diǎn)。  /// </summary>  [STAThread]  static void Main()  {   Application.EnableVisualStyles();   Application.SetCompatibleTextRenderingDefault(false);  // 啟動   SplashScreen.ShowSplashScreen();   // 進(jìn)行自己的操作:加載組件,加載文件等等   // 示例代碼為休眠一會   System.Threading.Thread.Sleep(3000);   // 關(guān)閉   if (SplashScreen.Instance != null)   {    SplashScreen.Instance.BeginInvoke(new MethodInvoker(SplashScreen.Instance.Dispose));   SplashScreen.Instance = null;   }   Application.Run(new FormMain());  } }

效果如下圖所示:

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 九台市| 加查县| 北流市| 沂源县| 河南省| 彩票| 大埔区| 云林县| 武定县| 定襄县| 肃宁县| 龙口市| 武宣县| 三江| 石景山区| 清水县| 四川省| 昭觉县| 江油市| 海南省| 怀集县| 阳泉市| 邮箱| 乌拉特中旗| 海原县| 贵州省| 禹城市| 高尔夫| 左权县| 垦利县| 靖安县| 石台县| 淮南市| 军事| 万宁市| 博客| 旅游| 新和县| 汾西县| 日照市| 沈丘县|