博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dev自带缓冲窗体效果的实现和控制
阅读量:7141 次
发布时间:2019-06-28

本文共 1980 字,大约阅读时间需要 6 分钟。

废话不多说代码送上:

       //添加// C:\Program Files\DevExpress 2011.2\Components\Bin\Framework\DevExpress.XtraEditors.v11.2.dll引用

       //缓冲控制对象
        private static SplashScreenManager _splashMgr = null;
        private object _lockobj = new object();
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>

        /// 显示缓冲窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //ShowSplan("正在加载数据");
            ShowWaitingWithTimer("正在加载数据", 8000);
        }

        /// <summary>

        /// 关闭缓冲窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            HideWaiting();
        }
        /// <summary>
        /// 显示缓冲窗体
        /// </summary>
        /// <param name="str"></param>
        private void ShowSplan(string str)
        {
            lock(_lockobj)
            {
                if (_splashMgr==null)
                {
                  
                    //创建缓冲窗体实例,如果已创建实例则跳过这一步
                    //WaitForm1(DEV窗体)
                    _splashMgr = new SplashScreenManager(typeof(WaitForm1), new SplashFormProperties());
                    _splashMgr.Properties.UseFadeInEffect=false;
                    _splashMgr.Properties.UseFadeOutEffect=false;
                }

                //指定缓冲窗体的父窗体对象

                _splashMgr.Properties.ParentForm=this;
                if (!_splashMgr.IsSplashFormVisible)
             {
             _splashMgr.ShowWaitForm();
             }
                _splashMgr.SetWaitFormDescription(str);
            }
        }

        protected void HideWaiting()

        {
            lock (_lockobj)
            {
                if (_splashMgr==null)
                {
                    return;
                }
                
                //当前正在显示缓冲界面,则关闭
                if (_splashMgr.IsSplashFormVisible)
                {
                    _splashMgr.CloseWaitForm();
                }
            }
       
        }

        protected static System.Windows.Forms.Timer WaitingTimer = null;
        /// <summary>
        /// 显示缓冲窗体(通过timer控件缓冲窗体的关闭)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="interval"></param>
        protected void ShowWaitingWithTimer(string msg, int interval)
        {
            this.ShowSplan(msg);

            //创建计时器

            if (WaitingTimer==null)
            {
                WaitingTimer = new Timer();
                WaitingTimer.Tick += (s, e1) =>
                {
                    HideWaiting();
                    WaitingTimer.Stop();
                };
            }

            //开启

            WaitingTimer.Interval = interval < 200 ? 500 : interval;
            WaitingTimer.Start();
        }

(拓展一下)实际开发中在基类窗体上完成上述功能,这样我们在子类窗体中就可以创建和控制缓冲窗体了.

转载于:https://www.cnblogs.com/nengge/archive/2013/06/08/3126693.html

你可能感兴趣的文章
eclipse修改 服务器默认路径
查看>>
[iOS Animation]-CALayer 视觉效果
查看>>
8 步搭建 Node.js + MongoDB 项目的自动化持续集成
查看>>
windowsserver 2012 R2 创建群集失败
查看>>
iostat和iowait详细解说--查看磁盘瓶颈
查看>>
wps的ppt放映时不能完全全屏的解决方法
查看>>
我的友情链接
查看>>
OC之self详解
查看>>
nginx ssl配置步骤
查看>>
Unity3d热更新(四):压缩文件
查看>>
sysctl.conf文件详解
查看>>
在连接中的EOF意味着什么?
查看>>
我的友情链接
查看>>
获得指定日期【月初和月末】
查看>>
Angular动画
查看>>
谈谈redis,memcache的区别和具体应用场景
查看>>
redis安装开发使用
查看>>
Java注解技术
查看>>
ArangoDB 3.2 Beta 版本发布,3项新特性为独家所有!
查看>>
java读取xml文件字段值
查看>>