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();

  • 相关阅读:
    ansible设置串行的方法
    给k8s集群中的node节点加标签
    Prometheus断电后启动异常 Error on ingesting samples
    配置 containerd 镜像仓库完全攻略
    这款网络排查工具,堪称神器!
    k8s备份工具之velero
    CentOS 7安装megacli
    Atitit .h5文件上传 v3
    php切片处理视频大文件思路
    php切片处理视频大文件功能
  • 原文地址:https://www.cnblogs.com/HeroBeast/p/1427295.html
Copyright © 2011-2022 走看看