Dev自带缓冲窗体效果的实现和控制
废话不多说代码送上:
//添加// C:\Program Files\DevExpress 2011.2\Components\Bin\Framework\DevExpress.XtraEditors.v11.2.dll引用
//缓冲控制对象
private static SplashScreenManager _splashMgr = null;
private object _lockobj = new object();
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 显示缓冲窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//ShowSplan("正在加载数据");
ShowWaitingWithTimer("正在加载数据", 8000);
}
/// <summary>
/// 关闭缓冲窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
HideWaiting();
}
/// <summary>
/// 显示缓冲窗体
/// </summary>
/// <param name="str"></param>
private void ShowSplan(string str)
{
lock(_lockobj)
{
if (_splashMgr==null)
{
//创建缓冲窗体实例,如果已创建实例则跳过这一步
//WaitForm1(DEV窗体)
_splashMgr = new SplashScreenManager(typeof(WaitForm1), new SplashFormProperties());
_splashMgr.Properties.UseFadeInEffect=false;
_splashMgr.Properties.UseFadeOutEffect=false;
}
//指定缓冲窗体的父窗体对象
_splashMgr.Properties.ParentForm=this;
if (!_splashMgr.IsSplashFormVisible)
{
_splashMgr.ShowWaitForm();
}
_splashMgr.SetWaitFormDescription(str);
}
}
protected void HideWaiting()
{
lock (_lockobj)
{
if (_splashMgr==null)
{
return;
}
//当前正在显示缓冲界面,则关闭
if (_splashMgr.IsSplashFormVisible)
{
_splashMgr.CloseWaitForm();
}
}
}
protected static System.Windows.Forms.Timer WaitingTimer = null;
/// <summary>
/// 显示缓冲窗体(通过timer控件缓冲窗体的关闭)
/// </summary>
/// <param name="msg"></param>
/// <param name="interval"></param>
protected void ShowWaitingWithTimer(string msg, int interval)
{
this.ShowSplan(msg);
//创建计时器
if (WaitingTimer==null)
{
WaitingTimer = new Timer();
WaitingTimer.Tick += (s, e1) =>
{
HideWaiting();
WaitingTimer.Stop();
};
}
//开启
WaitingTimer.Interval = interval < 200 ? 500 : interval;
WaitingTimer.Start();
}
(拓展一下)实际开发中在基类窗体上完成上述功能,这样我们在子类窗体中就可以创建和控制缓冲窗体了.
浙公网安备 33010602011771号