C# 自定义等待窗口

        private SynchronizationContext syncContext = null;

        public WaitWindow()
        {
            InitializeComponent();
            syncContext = SynchronizationContext.Current;
        }

        private void DisplayProgress()
        {
            while (true)
            {
                syncContext.Post(delegate (object target)
                {
                    Label lProgress = (Label)target;

                    if (lProgress.Left + lProgress.Width >= Width)
                    {
                        lProgress.Left = 0;
                    }
                    else
                    {
                        lProgress.Left += 10;
                    }
                }, lblProgress);
                Thread.Sleep(100);
            }
        }

        //waitWnd = new WaitWindow();
        //waitWnd.Owner = this;
        //waitWnd.Show();

        //if (waitWnd != null)
        //{
        //    waitWnd.Close();
        //}
        private void WaitWindow_Load(object sender, EventArgs e)
        {
            Thread runProgressThread = new Thread(new ThreadStart(DisplayProgress));
            runProgressThread.IsBackground = true;
            runProgressThread.Start();
        }

 

posted @ 2015-11-20 09:01  bobo-bobo  阅读(524)  评论(0编辑  收藏  举报