為提升用戶體驗,改造了一下原作者的東西 (樣式沒變,抽取了有用的代碼)
改造前:
改造前.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();
相關的東西挺簡單的,如有興趣,請去 原作者 博客查看