欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

DevExpress之SplashScreen用法实例

程序员文章站 2024-02-13 09:59:34
本文实例展示了devexpress中splashscreen的用法,对于c#初学者来说有一定的参考借鉴价值,具体用法如下: 关键代码部分如下: using de...

本文实例展示了devexpress中splashscreen的用法,对于c#初学者来说有一定的参考借鉴价值,具体用法如下:

关键代码部分如下:

using devexpress.xtrasplashscreen;
using system;
namespace devexpressutilhelpv3
{
  /// <summary>
  /// 基于.net 3.0的 splashscreen工具类
  /// </summary>
  public static class splashscreentoolv3
  {
    private const bool fadein = false;
    private const bool fadeout = true;
    private const bool throwexceptionifisalreadyshown = false;
    private const bool throwexceptionifisalreadyclosed = false;

    /// <summary>
    /// showsplashscreen
    /// </summary>
    /// <param name="type">waitform</param>
    public static void showsplashscreen(type type)
    {
      closesplashscreen();
      splashscreenmanager.showform(null, type, fadein, fadeout, throwexceptionifisalreadyshown);
    }
    /// <summary>
    /// closesplashscreen
    /// </summary>
    public static void closesplashscreen()
    {
      if (splashscreenmanager.default != null)
      {
        //thread _task = new thread(() =>
        //{
        splashscreenmanager.closeform(throwexceptionifisalreadyclosed);
        //});
        //_task.start();
      }
    }
    /// <summary>
    /// setcaption
    /// </summary>
    /// <param name="caption">需要设置的title</param>
    public static void setcaption(string caption)
    {
      if (splashscreenmanager.default != null && !string.isnullorempty(caption))
      {
        splashscreenmanager.default.setwaitformcaption(caption);
      }
    }
    /// <summary>
    /// setdescription
    /// </summary>
    /// <param name="description">需要设置的文字提示信息</param>
    public static void setdescription(string description)
    {
      if (splashscreenmanager.default != null && !string.isnullorempty(description))
      {
        splashscreenmanager.default.setwaitformdescription(description);
      }
    }
  }
}

测试代码如下:

try
{
 splashscreentoolv3.showsplashscreen(typeof(waitform1));
 thread.sleep(5000);
 throw new exception("ccccccccc");
 ////thread.sleep(5000);
 //splashscreentoolv3.setcaption("正在开始下载....");
 ////splashscreencontroller.showsplashscreen();
 //thread _task1 = new thread(() =>
 //{
 //  for (int i = 0; i < 100; i++)
 //  {
 //    splashscreentoolv3.setdescription(i.tostring() + "%");
 //    thread.sleep(1000);
 //  }
 //});
 //thread _task2 = new thread(() =>
 //{
 //  for (int i = 0; i < 100; i++)
 //  {
 //    splashscreentoolv3.setcaption("测试.." + i);
 //    thread.sleep(500);
 //  }
 //});
 //_task1.start();
 //_task2.start();
}
catch (exception ex)
{
 messagebox.show(ex.message);
}
finally
{
 // splashscreencontroller.hidesplashscreen();
}

测试效果如下图所示:

DevExpress之SplashScreen用法实例

希望本文所述方法对打击的c#程序设计能有所帮助!