将Devexpress WaitForm显示为对话框

时间:2012-05-18 13:01:33

标签: c# devexpress

我想在用户中显示WaitForm,同时进行长时间的后台操作。

我使用Thread来完成这项工作,并在工作完成时通过事件获得通知。

在这种情况下,我想集成一个DevExpress WaitForm。

当作业开始时(从线程内部或外部)可以显示此表单,并且可以在完成事件触发时停止。

来自.ShowWaitForm的{​​{1}}只显示表单。如何在等待时使表单丢弃窗口消息?

例如:我不希望用户在等待时点击按钮和内容。

3 个答案:

答案 0 :(得分:1)

据我所知,WaitForm的当前实现不允许它显示为对话框。我have found建议提供此功能:SplashScreenManager - Provide the capability to display WaitForm as a modal dialog。因此,您可以跟踪它。

答案 1 :(得分:1)

你可以这样使用;

SplashScreenManager.ShowForm(typeof(WaitForm1));
........
your code
........
SplashScreenManager.CloseForm();

答案 2 :(得分:1)

您必须创建继承的表单并覆盖SetDescription()和SetCaption()。你会根据自己的喜好用一些图标或动画gif来装饰表单。 在下面的示例中,我创建了一个名为MyWaitForm的表单,我只是放了两个标签来显示描述和标题文本。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DXApplication1
{
    public partial class MyWaitForm : DevExpress.XtraWaitForm.WaitForm
    {
        public MyWaitForm()
        {
            InitializeComponent();
        }

        public override void SetDescription(string description)
        {
            base.SetDescription(description);

            lbDescription.Text = description;
        }

        public override void SetCaption(string caption)
        {
            base.SetCaption(caption);

            lbCaption.Text = caption;
        }
    }
}

这里是Visual Studio设计器中显示的MyWaitForm: enter image description here

之后,您将使用Devexpress代码示例来显示WaitForm

https://documentation.devexpress.com/#WindowsForms/CustomDocument10832

但将MyWaitForm类类型传递给SplashScreenManager.ShowForm()方法:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraSplashScreen;
using System.Threading;

namespace WaitForm_SetDescription {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void btnShowWaitForm_Click(object sender, EventArgs e) {
            //Open MyWaitForm!!!
            SplashScreenManager.ShowForm(this, typeof(MyWaitForm), true, true, false);

            //The Wait Form is opened in a separate thread. To change its Description, use the SetWaitFormDescription method.
            for (int i = 1; i <= 100; i++) {
                SplashScreenManager.Default.SetWaitFormDescription(i.ToString() + "%");
                Thread.Sleep(25);
            }

            //Close Wait Form
            SplashScreenManager.CloseForm(false);
        }
    }
}