当前位置:   article > 正文

等待窗口 or splash 窗体用法

splash form not on screen怎么解决

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

转载于:https://www.cnblogs.com/HeroBeast/archive/2009/04/01/1427295.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号