为提升用户体验,改造了一下原作者的东西 (样式没变,抽取了有用的代码)
改造前:
改造后 :
代码也挺简单的
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();
相关的东西挺简单的,如有兴趣,请去 原作者 博客查看