C# winform 等待窗体

2018-04-10  本文已影响0人  ZoneWonderful

为提升用户体验,改造了一下原作者的东西 (样式没变,抽取了有用的代码)
改造前:

改造前.png

改造后 :

改造后.png

代码也挺简单的

 public partial class Loadding : Form
    {
        private IAsyncResult _AsyncResult;
        private EventHandler<EventArgs> _Method;
        public Loadding()
        {
            InitializeComponent();
        }
        public Loadding(EventHandler<EventArgs> method)
        {
            InitializeComponent();
            _Method = method;

        }
        private static Loadding load = null;
        public static Loadding getInstance(EventHandler<EventArgs> method)
        {
            if (load == null || load.IsDisposed)
            {
                load = new Loadding(method);
            }
            return load;
        }

        private void OnShown(object sender, EventArgs e)
        {
            if (Win32.AnimateWindow(this.Handle, 100, Win32.AW_ACTIVATE | Win32.AW_VER_POSITIVE | Win32.AW_A))
            {
                //上到下特效显示  
                Win32.AnimateWindow(this.Handle, 100, Win32.AW_ACTIVATE);
            }
            _AsyncResult = _Method.BeginInvoke(null, null, null, null);
        }
        private void FormClose(object sender, EventArgs e)
        {
            if (Win32.AnimateWindow(this.Handle, 100, Win32.AW_HIDE | Win32.AW_VER_POSITIVE | Win32.AW_A))
            {
                //上到下特效显示  
                Win32.AnimateWindow(this.Handle, 100, Win32.AW_HIDE);
            }
        }
        private void _Timer_Tick(object sender, EventArgs e)
        {
            if (_AsyncResult.IsCompleted)
            {
                this.Close();
            }
        }
    }

调用:

Loadding l =Loadding.getInstance((obj, args) =>{
            // 进行相关的逻辑 请求网络等等   
            
  });
    l.ShowDialog();

相关的东西挺简单的,如有兴趣,请去 原作者 博客查看

上一篇下一篇

猜你喜欢

热点阅读