zoukankan      html  css  js  c++  java
  • splashform 显示 主窗体 正解

    下面是部分代码:
    
    AppStart 类,包含Main方法
    
    public class AppStart
    
    {
    
        public AppStart()
    
        {
    
        }
    
        [STAThread]
    
        static void Main(string[] args)
    
        {
    
            //    显示Splash窗体
    
            Splash.Show();
    
            DoStartup(args);
    
            //    关闭Splash窗体
    
            Splash.Close();
    
        }
    
        static void DoStartup(string[] args)
    
        {
    
            //    做需要的事情
    
            frmMain f = new frmMain();
    
            Application.Run(f);
    
        }
    
    }
    
    Splash功能类:
    
    public class Splash
    
    {
    
        static frmSplash MySplashForm = null;
    
        static Thread MySplashThread = null;
    
        static void ShowThread() 
    
        {
    
            MySplashForm = new frmSplash();
    
            Application.Run(MySplashForm);
    
        }
    
        static public void Show() 
    
        {
    
            if (MySplashThread != null)
    
                return;
    
            MySplashThread = new Thread(new ThreadStart(Splash.ShowThread));
    
            MySplashThread.IsBackground = true;
    
            MySplashThread.ApartmentState = ApartmentState.STA;
    
            MySplashThread.Start();
    
        }
    
        static public void Close() 
    
        {
    
            if (MySplashThread == null) return;
    
            if (MySplashForm == null) return;
    
            try 
    
            {
    
                MySplashForm.Invoke(new MethodInvoker(MySplashForm.Close));
    
            }
    
            catch (Exception) 
    
            {
    
            }
    
            MySplashThread = null;
    
            MySplashForm = null;
    
        }
    
        static public string Status 
    
        {
    
            set 
    
            {
    
                if (MySplashForm == null) 
    
                {
    
                    return;
    
                }
    
                MySplashForm.StatusInfo = value;
    
            }
    
            get 
    
            {
    
                if (MySplashForm == null) 
    
                {
    
                    throw new InvalidOperationException("Splash Form not on screen");
    
                }
    
                return MySplashForm.StatusInfo;
    
            }
    
        }
    
    }
    
    Splash 界面类:
    
    public class frmSplash : System.Windows.Forms.Form
    
    {
    
        private string _StatusInfo = "";
    
        
    
        public frmSplash()
    
        {
    
            InitializeComponent();
    
        }
    
        private void InitializeComponent()
    
        {
    
            // 
    
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));        
    
            //
    
        }
    
        public string StatusInfo 
    
        {
    
            set 
    
            {
    
                _StatusInfo = value;
    
                ChangeStatusText();
    
            }
    
            get 
    
            {
    
                return _StatusInfo;
    
            }
    
        }
    
        public void ChangeStatusText() 
    
        {
    
            try 
    
            {
    
                if (this.InvokeRequired) 
    
                {
    
                    this.Invoke(new MethodInvoker(this.ChangeStatusText));
    
                    return;
    
                }
    
                labStatus.Text = _StatusInfo;
    
            }
    
            catch (Exception e) 
    
            {
    
                //    异常处理
    
            }
    
        }
    
    }
    
    主界面类:
    
    public class frmMain : System.Windows.Forms.Form
    
    {
    
        public frmMain()
    
        {
    
            InitializeComponent();
    
        Splash.Status = "状态:载入初始化模块";
    
                System.Threading.Thread.Sleep(1000);
    
                
    
        Splash.Status = "状态:载入管理模块";
    
                System.Threading.Thread.Sleep(1000);
    
        Splash.Status = "状态:载入打印模块";
    
                System.Threading.Thread.Sleep(1000);
    
        Splash.Status = "状态:载入插件模块";
    
                System.Threading.Thread.Sleep(1000);
    
        Splash.Status = "状态:连接数据库";
    
                System.Threading.Thread.Sleep(1000);
    
        Splash.Close();
    
        }
    
    }
    

      

    趁年轻努力提高自己
  • 相关阅读:
    android viewpager嵌套使用photoview异常问题
    android mvp设计模式
    android webview处理h5打开本地文件浏览器的功能
    使用python进行新浪微博粉丝爬虫
    android之ViewPager修改滑动速度
    我眼中的“阿里月饼事件”
    奄奄一息雏鸟
    RPC(远程过程调用)的应用
    对于开源菜谱的思考
    我跟360上网导航的过招
  • 原文地址:https://www.cnblogs.com/chinatrust/p/4489270.html
Copyright © 2011-2022 走看看