zoukankan      html  css  js  c++  java
  • 等待窗口 or splash 窗体用法

    1.建立一个窗体

    public partial class StartCompare : Form
    {
            /// <summary>
            /// 当前状态
            /// </summary>
            private string _stateText = string.Empty;
            
            /// <summary>
            /// 当前状态
            /// </summary>
            public string StateText
            {
                get { return _stateText; }
                set 
                {
                    _stateText = value;
                    ChangeStateText();
                }
            }
    
    
            public StartCompare()
            {
                InitializeComponent();
            }
    
            public void ChangeStateText()
            {
                try
                {
                    if (this.InvokeRequired)
                    {
                        this.Invoke(new MethodInvoker(this.ChangeStateText));
                        return;
                    }
    
                    this.lbState.Text = _stateText;
                }
                catch (Exception e)
                {
                    //    异常处理
                    Logger.LogException(e);
                }
    
            }
        }
    

    2. splash窗体操作类

     public class Splash
     {
            static StartCompare MySplashForm = null;
            static Thread MySplashThread = null;
    
            static void ShowThread()
            {
                MySplashForm = new StartCompare();
                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.StateText = value;
                }
                get
                {
                    if (MySplashForm == null)
                    {
                        throw new InvalidOperationException("Splash Form not on screen");
                    }
                    return MySplashForm.StateText;
                }
            }
    
        }

    3.调用

     Splash.Show();
     //
     Splash.Status = "正在初始化版本比对,请稍后……";
     InitializeComponent();
      Splash.Status = "初始化完成,请稍后……";
     Splash.Close();

  • 相关阅读:
    8u111-jdk-alpine 字体缺少FontConfiguration的NullPointerException错误解决方案
    Mybatis插件原理
    Mybaits 分页
    @requestBody 和@RequestParam
    Mybaits 生产mapper
    powerDesigner 生成SQL时没有注释问题
    HashMap 的 put过程
    Java的锁
    Java1.8 JVM配置 GC日志输出
    Windows 安装两个MYSQL实例
  • 原文地址:https://www.cnblogs.com/HeroBeast/p/1427295.html
Copyright © 2011-2022 走看看