第一步: 主程式啟動主表單(這裡表示為 form1)
如下:
static class Program
{
/// <summary>
/// 應用程式的主進入點。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
第二步: 主表單( form1) 中的 _Load 事件中啟動歡迎介面 (form2)
如下:
private void Form1_Load(object sender, EventArgs e)
{
//啟動表單
Form2 MySplashForm = new Form2();
MySplashForm.ShowDialog();
}
第三步: 歡迎介面中控制介面的顯示方式並使用 timer 控制歡迎介面的消失時間 (實際中往往是讀取系統需要的配置資訊後消失)
如下:
private void Form2_Load(object sender, EventArgs e)
{
//設定啟動表單
this.FormBorderStyle = FormBorderStyle.None;
this.BackgroundImage = Image.FromFile("test.jpg");
this.timer1.Start();
this.timer1.Interval = 10000;
}
private void timer1_Tick(object sender, EventArgs e)
{
//...........讀取系統配置
//關閉啟動表單
this.Close();
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
//關閉定時器
this.timer1.Stop();
}