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);
this.splashScreenManager1 = new DevExpress.XtraSplashScreen.SplashScreenManager(this, typeof(global::SplashScreenAndWaitForm.WaitForm1), true, true, true);

private DevExpress.XtraSplashScreen.SplashScreenManager splashScreenManager1;

后台调用的方法有2中:

1.用SplashScreenManager.ShowForm()来显示

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

代码如下:

        public Form1()
        {
            SplashScreenManager.ShowForm(typeof(SplashScreen1));
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            InitializeComponent();
            SplashScreenManager.CloseForm();
        }

        private void btn_CustomSplash_Click(object sender, EventArgs e)
        {
            SplashScreenManager.CloseForm(false);
            splashScreenManager1.ShowWaitForm();
            //SplashScreenManager.ShowForm(typeof(WaitForm1));
            Thread.Sleep(3000);
            SplashScreenManager.CloseForm();
            //splashScreenManager1.CloseWaitForm();
        }

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

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

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

splashscreen界面代码;

#region Overrides

        public override void ProcessCommand(Enum cmd, object arg)
        {
            base.ProcessCommand(cmd, arg);
            SplashScreenCommand command = (SplashScreenCommand)cmd;
            if (command == SplashScreenCommand.SetProgress)
            {
                int pos = (int)arg;
                marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = pos;
            }
            if (command == SplashScreenCommand.InitView)
            {
                labelControl2.Text =Convert.ToString(arg);
                marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = 50;
                marqueeProgressBarControl1.Properties.ProgressAnimationMode = ProgressAnimationMode.PingPong;
                //marqueeProgressBarControl1.Properties.Paused = true;
                //marqueeProgressBarControl1.Properties.Stopped = true;
            }
            if (command==SplashScreenCommand.Command3)
            {
                ProgressViewStyle style = (ProgressViewStyle)arg;
                labelControl2.Text = "最终初始化";
                marqueeProgressBarControl1.Properties.MarqueeAnimationSpeed = 100;
                marqueeProgressBarControl1.Properties.ProgressViewStyle = style;
                //marqueeProgressBarControl1.Refresh();
            }
        }

        #endregion

        public enum SplashScreenCommand
        {
            SetProgress,
            InitView,
            Command3
        }

form1代码如下:

        private void btn_CustomSplash_Click(object sender, EventArgs e)
        {
            //SplashScreenManager.CloseForm(false);
            //splashScreenManager1.ShowWaitForm();
            //SplashScreenManager.ShowForm(typeof(WaitForm1));
            //Thread.Sleep(3000);
            //SplashScreenManager.CloseForm();
            //splashScreenManager1.CloseWaitForm();

            //ProcessCommand和SendCommang用法
            SplashScreenManager.ShowForm(this, typeof(CustomSplash), true, true, false);

            // The splash screen will be opened in a separate thread. To interact with it, use the SendCommand method. 
            SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.SetProgress, 300);
            //To process commands, override the SplashScreen.ProcessCommand method. 
            Thread.Sleep(2500);

            SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.InitView, "初始化");
            Thread.Sleep(2500);

            SplashScreenManager.Default.SendCommand(CustomSplash.SplashScreenCommand.Command3, ProgressViewStyle.Solid);
            Thread.Sleep(2500);

            // Close the Splash Screen. 
            SplashScreenManager.CloseForm(false);

        }

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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值