How to use SplashScreenManager in C#

By FoxLearn 12/1/2024 5:00:20 AM   8.96K
DevExpress SplashScreenManager is a powerful tool for displaying splash screens or wait forms in your application.

Using DevExpress, you can enhance your application's user experience by adding a custom wait form to indicate progress during lengthy operations. Below, we’ll walk through creating and using a custom wait form (frmWaitForm) in a Windows Forms application.

How to use SplashScreenManager in C#?

Open Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "ProgressIndicatorExample" and then click OK

Design your form as shown below.

frmWaitForm

c# waitform dialog

Form1

devexpress watiform dialog

The frmWaitForm inherits from DevExpress.XtraWaitForm.WaitForm and is the central component for displaying progress messages. The code below demonstrates how to customize this form.

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

namespace ProgressIndicatorExample
{
    public partial class frmWaitForm : WaitForm
    {
        public frmWaitForm()
        {
            InitializeComponent();
            this.progressPanel1.AutoHeight = true;
        }

        #region Overrides

        public override void SetCaption(string caption)
        {
            // Set the caption text dynamically
            base.SetCaption(caption);
            this.progressPanel1.Caption = caption;
        }
        public override void SetDescription(string description)
        {
            // Set the description text dynamically
            base.SetDescription(description);
            this.progressPanel1.Description = description;
        }
        public override void ProcessCommand(Enum cmd, object arg)
        {
            base.ProcessCommand(cmd, arg);
        }

        #endregion

        public enum WaitFormCommand
        {
        }
    }
}

In your main form, you can display the wait form during a long-running operation. The following example shows how to integrate the frmWaitForm using a button click event.

private void simpleButton1_Click(object sender, EventArgs e)
{
    // Show the wait form
    SplashScreenManager.ShowForm(this, typeof(frmWaitForm), true, true, false);
    // Update wait form caption
    SplashScreenManager.Default.SetWaitFormCaption("Processing data...");
    // Simulate a lengthy operation
    for (int i = 0; i < 100; i++)
    {
        //Add your code here
        Thread.Sleep(10);//Only for demo
    }
    // Close the wait form
    SplashScreenManager.CloseForm();
}

Use SplashScreenManager.ShowForm to display frmWaitForm.

Use SplashScreenManager.CloseForm to ensure the wait form is closed once the operation completes.

By combining the custom wait form frmWaitForm with the SplashScreenManager, you can create an elegant progress indicator for your DevExpress-based Windows Forms applications.

VIDEO TUTORIAL