学习010-04-04-04 Use a Custom Class to Show a Splash Form (WinForms)(使用自定义类显示启动窗体(Windows 窗体))

Use a Custom Class to Show a Splash Form (WinForms)(使用自定义类显示启动窗体(Windows 窗体))

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.
在解决方案的WinForms应用程序项目中创建一个新的Windows表单,将表单命名为SplashScreenForm,并对其进行设计以满足您的要求。
在这里插入图片描述

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.
要将设计器工具用于DevExpress控件。NET应用程序,请从本地NuGet提要或https://nuget.devexpress.com的远程NuGet提要安装DevExpress.Win.Design包。

2.Add a new class to your WinForms Application Project and implement the ISplash interface.
将一个新类添加到您的WinForms应用程序项目并实现ISplash接口。

  • Override the ISplash.Start method. Create a SplashScreenForm instance and call the form’s Show method.
    覆盖ISplash. Start方法。创建一个SplashScreenForm实例并调用表单的Show方法。
  • In the ISplash.Stop method’s override, hide and close the SplashScreenForm.
    在ISplash. Stop方法的覆盖中,隐藏并关闭SplashScreenForm。
  • The ISplash.IsStarted property indicates whether the SplashScreenForm is shown.
    ISplash. IsStarted属性指示是否显示SplashScreenForm。
  • Override ISplash.SetDisplayText. You can call this method to change the SplashScreenForm’s text.
    覆盖ISplash. SetDisplayText。您可以调用此方法来更改SplashScreenForm的文本。

The code below demonstrates the MySplash class that implements the ISplash interface.
下面的代码演示了实现ISplash接口的MySplash类。

C# 
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 file. Set the SplashScreen property to a new MySplash class instance.
访问WinApplication. cs文件。将SplashScreen属性设置为新的MySplash类实例。

C# 
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.
您可以显示加载进度信息。为此,请在MySplash类中实现ISupportUpdateSplash接口,并将UpdateInfo方法添加到SplashScreenForm类。

C# 
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.
启动应用程序以查看结果。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汤姆•猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值