DevExpress窗体加载等待
using DevExpress.XtraEditors; using DevExpress.XtraSplashScreen; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace FirstDevExpressPro { public partial class FrmMain : DevExpress.XtraEditors.XtraForm { public FrmMain() { InitializeComponent(); }//加载窗体 private void simpleButton1_Click(object sender, EventArgs e) { this.ShowWait<XtraForm1>();//通过扩展就可以直接通过this调用,XtraForm1为要打开的窗体的Name } } /// <summary> /// 通用窗体加载类 /// </summary> public static class Common { /// <summary> /// 静态类中在Form前添加this表示扩展 /// </summary> /// <typeparam name="T">泛型窗体</typeparam> /// <param name="form"></param> /// <param name="caption"></param> /// <param name="Description"></param> public static void ShowWait<T>(this Form form, String caption="加载中",string Description="请等待") { //设置淡入淡出效果,WaitForm1为DevXepress等待窗体控件(可以通过右键项目---》Add DevExpress Item---》New Item) SplashScreenManager splash = new SplashScreenManager(form, typeof(WaitForm1), true, true); splash.ShowWaitForm();//显示等待窗体 splash.SplashFormStartPosition = SplashFormStartPosition.CenterScreen; splash.SetWaitFormCaption(caption); splash.SetWaitFormDescription(Description); #region 通过泛型和反射传递进来一个窗体类型 Type type = typeof(T);//检测类型 Form f = (Form)Activator.CreateInstance(type);//相当于new f.Show(); #endregion splash.CloseWaitForm();//关闭等待窗体 } } }
上面封装了一个窗体加载等待的方法,我们通过他来打开一个比较耗时的窗体,先打开主窗体,然后点击加载窗体:
然后开始加载窗体,如下
4556