
DevExpress使用WaitForm等待加载窗体
DevExpress中除过WaitDialogForm,还有WaitForm,也可以实现此功能,WaitForm比WaitDialogForm更加的强大。1.建立一个项目2.增加 WaitForm窗体。右键项目选择New Item选择如图所示这个是修改字体的颜色这个是修改窗体的样式,有4种样式可以选择3.在代码中增加public void ShowMe(Form owner, string des
·
DevExpress中除过WaitDialogForm,还有WaitForm,也可以实现此功能,WaitForm比WaitDialogForm更加的强大。
1.建立一个项目
2.增加 WaitForm窗体。
右键项目选择New Item
选择如图所示
这个是修改字体的颜色
这个是修改窗体的样式,
有4种样式可以选择
3.在代码中增加
public void ShowMe(Form owner, string description, string caption)
{
SplashScreenManager.ShowForm(owner, typeof(WaitForm1), true, true, false);
SplashScreenManager.Default.SetWaitFormDescription(description);//描述
SplashScreenManager.Default.SetWaitFormCaption(caption);//标题
}
public void ShowMe(Form owner)
{
SplashScreenManager.ShowForm(owner, typeof(WaitForm1), true, true, false);
}
public void HideMe(Form owner)
{
SplashScreenManager.CloseForm(false, 0, owner);
}
4.WaitForm1中所有的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraSplashScreen;
using DevExpress.XtraWaitForm;
namespace WindowsFormsApp1
{
public partial class WaitForm1 : WaitForm
{
public WaitForm1()
{
InitializeComponent();
this.progressPanel1.AutoHeight = true;
}
#region Overrides
public override void SetCaption(string caption)
{
base.SetCaption(caption);
this.progressPanel1.Caption = caption;
}
public override void SetDescription(string description)
{
base.SetDescription(description);
this.progressPanel1.Description = description;
}
public override void ProcessCommand(Enum cmd, object arg)
{
base.ProcessCommand(cmd, arg);
}
#endregion
public enum WaitFormCommand
{
}
public void ShowMe(Form owner, string description, string caption)
{
SplashScreenManager.ShowForm(owner, typeof(WaitForm1), true, true, false);
SplashScreenManager.Default.SetWaitFormDescription(description);//描述
SplashScreenManager.Default.SetWaitFormCaption(caption);//标题
}
public void ShowMe(Form owner)
{
SplashScreenManager.ShowForm(owner, typeof(WaitForm1), true, true, false);
}
public void HideMe(Form owner)
{
SplashScreenManager.CloseForm(false, 0, owner);
}
}
}
5.回到项目的主界面中,在按钮下面增加以下代码
using DevExpress.XtraSplashScreen;
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WaitForm1 waitForm1 = new WaitForm1();
waitForm1.ShowMe(this, "123", "456");
for (int i = 1; i <= 5; i++)//处理数据
{
Thread.Sleep(1000);
}
waitForm1.HideMe(this);
}
}
}
6.效果
拓展功能
在进入软件的时候,先进行加载,然后再进入软件的主界面
1.在程序入口Program中增加如下代码
SplashScreenManager.ShowForm(typeof(WaitForm1));
Thread.Sleep(5000);
2.在主界面中,增加load事件,增加如下代码
SplashScreenManager.CloseForm(true);
3.效果
更多推荐
所有评论(0)