1.
采用事件委托的方法對象:主窗體:FrmMain 加載窗體:FrmLoading思路:在主窗體加載前顯示窗體FrmLoading,當(dāng)主窗體加載完畢后(第一次顯示的時(shí)候),關(guān)閉FrmLoading
C# 代碼如下所示
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace CDemoTest{ public partial class FrmMain : Form { PRivate FrmLoading loadForm; public FrmMain() { //創(chuàng)建加載窗體 loadForm = new FrmLoading(); //指定窗體加載完畢時(shí)的事件 this.Shown += FrmLoading_Close; loadForm.Show(); //主窗體初始化方法 InitializeComponent(); } //聲明關(guān)閉加載窗體方法 private void FrmLoading_Close(object sender, EventArgs e) { loadForm.Close(); } private void FrmMain_Load(object sender, EventArgs e) { Thread.Sleep(3000); } }}
2.
1.在Main方法中,先顯示啟動(dòng)畫面,注意使用Show而非ShowDialog。2.然后按照正常的方式,application.Run(mainForm);3.在mainForm的構(gòu)造函數(shù)中,啟動(dòng)加載線程。4.mainForm中設(shè)置一個(gè)標(biāo)志,如果加載完成,該標(biāo)志設(shè)置為某值。5.作為啟動(dòng)畫面使用的form,注意檢測mainForm中的標(biāo)志,如果主窗體加載完成,它自己關(guān)閉。
感覺方法比較好,記錄一下。
新聞熱點(diǎn)
疑難解答
圖片精選