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)備來(lái)接受程序加載的緩慢,還可以讓用戶知道加載的進(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)文章
c#圖片縮放圖片剪切功能實(shí)現(xiàn)(等比縮放)
c#圖片縮放剪切功能實(shí)現(xiàn),代碼中包含了c#圖片處理的一些基礎(chǔ)知識(shí),與大家分享2013-12-12
詳解如何獲取C#類中發(fā)生數(shù)據(jù)變化的屬性信息
這篇文章主要介紹了詳解如何獲取C#類中發(fā)生數(shù)據(jù)變化的屬性信息,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
C#語(yǔ)法相比其它語(yǔ)言比較獨(dú)特的地方(二)
這篇文章主要介紹了C#語(yǔ)法相比其它語(yǔ)言比較獨(dú)特的地方(二),本文講解了internal與protected、private、enum、string的==、傳引用等內(nèi)容,需要的朋友可以參考下2015-04-04

