C# 實現啓動歡迎界面的簡單方法

第一步: 主程序啓動主窗體(這裏表示爲 form1)
如下:
    static class Program
    {
        /// <summary>
        /// 應用程序的主入口點。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
第二步: 主窗體( form1) 中的 _Load 事件中啓動歡迎界面 (SplashForm)
如下:
        private void Form1_Load(object sender, EventArgs e)
        {
            //啓動窗體
            SplashForm MySplashForm = new SplashForm ();
            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 SplashForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            //關閉定時器
            this.timer1.Stop();
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章