C#中載入介面的幾種做法

來源:互聯網
上載者:User

標籤:io   os   使用   ar   for   sp   art   on   cti   

1.

採用事件委託的方法  
對象:主表單:FrmMain 載入表單:FrmLoading  
思路:  
在主表單載入前顯示表單FrmLoading,當主表單載入完畢後(第一次顯示的時候),關閉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()
        {
            //建立載入表單             loadForm = new FrmLoading();
            //指定表單載入完畢時的事件
            this.Shown += FrmLoading_Close;


            loadForm.Show();
            //主表單初始化方法
            InitializeComponent();
        }




        //聲明關閉載入表單方法
        private void FrmLoading_Close(object sender, EventArgs e)
        {
            loadForm.Close();
        }


        private void FrmMain_Load(object sender, EventArgs e)
        {


            Thread.Sleep(3000);

        }
    }
}

 

2.

1.在Main方法中,先顯示啟動畫面,注意使用Show而非ShowDialog。
2.然後按照正常的方式,Application.Run(mainForm);
3.在mainForm的建構函式中,啟動載入線程。
4.mainForm中設定一個標誌,如果載入完成,該標誌設定為某值。
5.作為啟動畫面使用的form,注意檢測mainForm中的標誌,如果主表單載入完成,它自己關閉。

 

感覺方法比較好,記錄一下。

 

C#中載入介面的幾種做法

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.