当前位置:   article > 正文

SplashScreen和WaitForm使用_vs2019 工具箱没有splashscreen和waitform

vs2019 工具箱没有splashscreen和waitform

splashscreen和waitForm一般用于需要等待得情况,一般,splashscreen用于程序启动得等待界面,而waitform则用于数据加载等耗时情况下,下面,先给出一种通用得添加方法:

要向程序中,添加这两个控件,可以再工具箱中搜索SplashScreenManager控件,并将其拖入到相应得窗体中,如图所示,如果我们可以将Splash Screen Manager拖入到Form1中,

如图所示,点击Add Splash Screen,则会在资源管理器中生成一个Splash Screen得实例SplashScreen1,点击WaitForm同理,会生成WaitForm得实例,属性的话可以参照这里的属性图

这里主要对Active Splash Form进行说明,如果设置为none,则窗体不会显示任何的效果,若选择SplashScreen1,不必做其他操作,在程序启动时,即会有加载窗口,若选择waitForm1,不会有加载效果,但是,这两个选项,在designer文件下生成的代码略有不同,选择waitForm1时,会在designer中生成SplashScreenManager的实例,而选择splash Screen1则不会,具体原因还不知道。代码分别如下:

DevExpress.XtraSplashScreen.SplashScreenManager splashScreenManager1 = new DevExpress.XtraSplashScreen.SplashScreenManager(this, typeof(global::SplashScreenAndWaitForm.SplashScreen1), true, true, true);
  1. this.splashScreenManager1 = new DevExpress.XtraSplashScreen.SplashScreenManager(this, typeof(global::SplashScreenAndWaitForm.WaitForm1), true, true, true);
  2. private DevExpress.XtraSplashScreen.SplashScreenManager splashScreenManager1;

后台调用的方法有2中:

1.用SplashScreenManager.ShowForm()来显示

2.用SplashScreenManager的实例中的方法来显示

代码如下:

  1. public Form1()
  2. {
  3. SplashScreenManager.ShowForm(typeof(SplashScreen1));
  4. SplashScreenManager.ShowForm(typeof(WaitForm1));
  5. InitializeComponent();
  6. SplashScreenManager.CloseForm();
  7. }
  8. private void btn_CustomSplash_Click(object sender, EventArgs e)
  9. {
  10. SplashScreenManager.CloseForm(false);
  11. splashScreenManager1.ShowWaitForm();
  12. //SplashScreenManager.ShowForm(typeof(WaitForm1));
  13. Thread.Sleep(3000);
  14. SplashScreenManager.CloseForm();
  15. //splashScreenManager1.CloseWaitForm();
  16. }

其实,splashScreen和WaitForm的用法还是比较简单的。

更高级的用法,可以使用WaitFormCommand/SplashScreenCommand来定义要执行的命令,具体还在学习中,随后更新。

经过一番研究,发现,这个方法可以如下使用:

splashscreen界面代码;

  1. #region Overrides
  2. public override void ProcessCommand(Enum cmd, object arg)
  3. {
  4. base.ProcessCommand(cmd, arg);
  5. SplashScreenCommand command = (SplashScreenCommand)cmd;
  6. if (command == SplashScreenCommand.SetProgress)
  7. {
  8. int pos = (int)arg;
  9. marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = pos;
  10. }
  11. if (command == SplashScreenCommand.InitView)
  12. {
  13. labelControl2.Text =Convert.ToString(arg);
  14. marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = 50;
  15. marqueeProgressBarControl1.Properties.ProgressAnimationMode = ProgressAnimationMode.PingPong;
  16. //marqueeProgressBarControl1.Properties.Paused = true;
  17. //marqueeProgressBarControl1.Properties.Stopped = true;
  18. }
  19. if (command==SplashScreenCommand.Command3)
  20. {
  21. ProgressViewStyle style = (ProgressViewStyle)arg;
  22. labelControl2.Text = "最终初始化";
  23. marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = 100;
  24. marqueeProgressBarControl1.Properties.ProgressViewStyle = style;
  25. //marqueeProgressBarControl1.Refresh();
  26. }
  27. }
  28. #endregion
  29. public enum SplashScreenCommand
  30. {
  31. SetProgress,
  32. InitView,
  33. Command3
  34. }

form1代码如下:

  1. private void btn_CustomSplash_Click(object sender, EventArgs e)
  2. {
  3. //SplashScreenManager.CloseForm(false);
  4. //splashScreenManager1.ShowWaitForm();
  5. //SplashScreenManager.ShowForm(typeof(WaitForm1));
  6. //Thread.Sleep(3000);
  7. //SplashScreenManager.CloseForm();
  8. //splashScreenManager1.CloseWaitForm();
  9. //ProcessCommand和SendCommang用法
  10. SplashScreenManager.ShowForm(this, typeof(CustomSplash), true, true, false);
  11. // The splash screen will be opened in a separate thread. To interact with it, use the SendCommand method.
  12. SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.SetProgress, 300);
  13. //To process commands, override the SplashScreen.ProcessCommand method.
  14. Thread.Sleep(2500);
  15. SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.InitView, "初始化");
  16. Thread.Sleep(2500);
  17. SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.Command3, ProgressViewStyle.Solid);
  18. Thread.Sleep(2500);
  19. // Close the Splash Screen.
  20. SplashScreenManager.CloseForm(false);
  21. }

具体的使用场景的还得考各位去琢磨,本篇暂时到这里了,随后会统一将文章里的代码上传到GitHub,有需要者可自取,或者留言给我亦可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/309485
推荐阅读
相关标签
  

闽ICP备14008679号