c#制作簡(jiǎn)單啟動(dòng)畫面的方法
本文實(shí)例講述了c#制作簡(jiǎn)單啟動(dòng)畫面的方法。分享給大家供大家參考。具體分析如下:
啟動(dòng)畫面是程序啟動(dòng)加載組件時(shí)一個(gè)讓用戶稍微耐心等待的提示框。一個(gè)好的軟件在有啟動(dòng)等待需求時(shí)必定做一個(gè)啟動(dòng)畫面。啟動(dòng)畫面可以讓用戶有心理準(zhǔn)備來接受程序加載的緩慢,還可以讓用戶知道加載的進(jìn)度和內(nèi)容。本文只是記錄最簡(jiǎn)單的構(gòu)架。
VS2010創(chuàng)建一個(gè)C# Windows窗體應(yīng)用程序,將主窗體改名為FormMain,再創(chuàng)建一個(gè)窗體起名為SplashScreen。向程序中加載一個(gè)圖片作為啟動(dòng)畫面,如下圖
然后編輯SplashScreen.cs代碼
/// <summary> /// 啟動(dòng)畫面 /// </summary> public partial class SplashScreen : Form { /// <summary> /// 啟動(dòng)畫面本身 /// </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 = "啟動(dòng)畫面:我們正在努力的加載程序,請(qǐng)稍后..."; 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(); } }
然后在主程序啟動(dòng)時(shí)調(diào)用
static class Program { /// <summary> /// 應(yīng)用程序的主入口點(diǎn)。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // 啟動(dòng) SplashScreen.ShowSplashScreen(); // 進(jìn)行自己的操作:加載組件,加載文件等等 // 示例代碼為休眠一會(huì) 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()); } }
效果如下圖所示:
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C#實(shí)現(xiàn)將應(yīng)用程序設(shè)置為開機(jī)啟動(dòng)的方法
- C#設(shè)置開機(jī)啟動(dòng)項(xiàng)、取消開機(jī)啟動(dòng)項(xiàng)
- C#代碼設(shè)置開機(jī)啟動(dòng)示例
- c# 開機(jī)啟動(dòng)項(xiàng)的小例子
- C#實(shí)現(xiàn)開機(jī)自動(dòng)啟動(dòng)設(shè)置代碼分享
- C#實(shí)現(xiàn)啟動(dòng),關(guān)閉與查找進(jìn)程的方法
- C#實(shí)現(xiàn)在啟動(dòng)目錄創(chuàng)建快捷方式的方法
- C#實(shí)現(xiàn)進(jìn)程管理的啟動(dòng)和停止實(shí)例
- C#啟動(dòng)進(jìn)程的幾種常用方法
- C#實(shí)現(xiàn)程序開機(jī)啟動(dòng)的方法
相關(guān)文章
Unity Shader實(shí)現(xiàn)動(dòng)態(tài)霧效果
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)動(dòng)態(tài)霧效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04C#使用foreach遍歷哈希表(hashtable)的方法
這篇文章主要介紹了C#使用foreach遍歷哈希表(hashtable)的方法,是C#中foreach語句遍歷散列表的典型應(yīng)用,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04C#實(shí)現(xiàn)通過ffmpeg從flv視頻文件中截圖的方法
這篇文章主要介紹了C#實(shí)現(xiàn)通過ffmpeg從flv視頻文件中截圖的方法,實(shí)例分析了C#使用ffmpeg操作flv文件的技巧,需要的朋友可以參考下2015-03-03