Skip to main content

Use a Custom Class to Show a Splash Form (WinForms)

  • 3 minutes to read

This topic demonstrates how create a custom splash form and use a custom class to show this form.

  1. Create a new Windows Form in your solution’s WinForms Application project, name the form SplashScreenForm, and design it to meet your requirements.

    Splash

    Note

    To use designer tools for DevExpress controls in .NET applications, install the DevExpress.Win.Design package from the local NuGet feed, or from a remote NuGet feed at https://nuget.devexpress.com.

  2. Add a new class to your WinForms Application Project and implement the ISplash interface.

    • Override the ISplash.Start method. Create a SplashScreenForm instance and call the form’s Show method.
    • In the ISplash.Stop method’s override, hide and close the SplashScreenForm.
    • The ISplash.IsStarted property indicates whether the SplashScreenForm is shown.
    • Override ISplash.SetDisplayText. You can call this method to change the SplashScreenForm‘s text.

    The code below demonstrates the MySplash class that implements the ISplash interface.

    using DevExpress.ExpressApp.Win;
    //...
    public class MySplash : ISplash {
        static private SplashScreenForm form;
        private static bool isStarted = false;
        public void Start() {
            isStarted = true;
            form = new SplashScreenForm();
            form.Show();
            System.Windows.Forms.Application.DoEvents();
        }
        public void Stop() {
            if(form != null) {
                form.Hide();
                form.Close();
                form = null;
            }
            isStarted = false;
        }
        public void SetDisplayText(string displayText) {
        }
        public bool IsStarted {
            get { return isStarted; }
        }
    }
    
  3. Access the WinApplication.cs (WinApplication.vb) file. Set the SplashScreen property to a new MySplash class instance.

    public MySolutionWindowsFormsApplication() {
       //...
       SplashScreen = new MySplash();
       // ...
    }
    
  4. You can display loading progress information. To do this, implement the the ISupportUpdateSplash interface in the MySplash class and add the UpdateInfo method to the SplashScreenForm class.

    public class MySplash : ISplash, ISupportUpdateSplash {
        // ...
        public void UpdateSplash(string caption, string description, params object[] additionalParams) {
            form.UpdateInfo(description);
        }
    }
    // ...
    public partial class SplashScreenForm : Form {
        // ...
        internal void UpdateInfo(string info) {
            label2.Text = info;
        }
    }
    
  5. Start the application to see the result.

    CustomSplashForm