Odys
Odys

Reputation: 9090

Show Devexpress WaitForm as dialog

I want to show a WaitForm in the user and in the meantime do a long background operation.

I use a Thread for this job and get notified using an event on when the job has been completed.

In this scenario I want to integrate a DevExpress WaitForm.

This form can be shown when the job is going to start (either from inside or outside the thread) and can be stopped upon the completion event fires.

The .ShowWaitForm from SplashScreenManager just shows the form. How can I make the form discard window messages while waiting?

Eg: I don't want the user to be able to click buttons and stuff while waiting.

Upvotes: 1

Views: 13890

Answers (3)

Massimo
Massimo

Reputation: 147

You must create your inherited form and override the SetDescription() and SetCaption(). You will decorate the form with some icon or animated gif as you prefer. In the following example I created a form named MyWaitForm and I simply put two labels showing the description and caption text.

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;
        }
    }
}

Here the MyWaitForm as shown in the Visual Studio designer: enter image description here

After that you will use the Devexpress code sample to show the WaitForm

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

but passing your MyWaitForm class type to the SplashScreenManager.ShowForm() method:

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);
        }
    }
}

Upvotes: 2

Sinan Chik
Sinan Chik

Reputation: 81

You can use like this ;

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

Upvotes: 1

DmitryG
DmitryG

Reputation: 17848

As far as I know current implementation of the WaitForm does not allow it to be displayed as a dialog. I have found a suggestion to provide this functionality: SplashScreenManager - Provide the capability to display WaitForm as a modal dialog. Thus you can track it.

Upvotes: 1

Related Questions