如何在智慧型裝置應用程式執行時,顯示起始畫面 ( Splash Screen )
更多文章,請到我在點部落所建立的部落格「.NET菜鳥自救會」閱讀
http://www.dotblogs.com.tw/chou/
問題描述
如何在智慧型裝置應用程式執行時,顯示起始畫面 ( Splash Screen )
方法
(1) 新增 Form 作為 Splash Screen Form
![]()
(2) 流程
先在 Splash Screen Form 上加入 PictureBox 控制項,並且加入要作為 Splash Screen,並將 PictureBox 設定為 停駐於父容器中,假如圖片不夠大,也可以設定 SizeMode 為 StretchImage,下圖為 Splash Screen Form
![]()
在主程式表單初始化前,先顯示 Splash Screen Form,並且隔幾秒後,關閉 Splash Screen 表單,而後主程式表單顯示。
程式碼
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SmartDeviceSplashScreen
{
    public partial class Form1 : Form
    {
        FormSplashScreen fss;
        public Form1()
        {
            fss = new FormSplashScreen();  // 實例化 FormSplashScreen 表單
            fss.Owner = this;   // 將此表單的擁有者設定給主程式表單
            fss.WindowState = FormWindowState.Maximized;  // 設定 FormSplashScreen 表單最大化
            fss.Show();  // 顯示 FormSplashScreen 表單
            Application.DoEvents();  // 處理目前在訊息佇列中的所有 Windows 訊息
            this.Visible = false;  // 主程式表單不可見
            this.Enabled = false;  // 主程式表單不可回應使用者
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);  // FormSplashScreen 顯示5秒
            this.Visible = true;  // 主程式表單可見
            this.Enabled = true;  // 主程式表單可回應使用者
            fss.Close();  // 關閉 FormSplashScreen 表單
        }
    }
}
五秒後,顯示主程式表單
![]()