程 序 人 生

[每个人都是工程师,书写着属于自己的人生代码!--林海]
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Movie类

Posted on 2011-03-08 13:56  林海  阅读(160)  评论(0编辑  收藏  举报

/// <summary>
    /// 3D动画类
    /// </summary>
    public class Movie
    {
        Timer _timer = new Timer();

        public Movie()
        {
            _timer.Enabled = false;
            _timer.Tick += new EventHandler(timer_Tick);
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if(Refrash!=null)
                Refrash();
            //如果有计数
            if (_RunTimes >= 1)
            {
                _nowCount++;
                //到达次数
                if (_nowCount == _RunTimes)
                    IsRunning = false;
            }
        }

        /// <summary>
        /// 运行状态
        /// </summary>
        public bool IsRunning
        {
            get { return _timer.Enabled; }
            set { _timer.Enabled = value; }
        }

        /// <summary>
        /// 刷新的动作
        /// </summary>
        public Action Refrash;

        /// <summary>
        /// 执行刷新动作的间隔时间(毫秒)
        /// </summary>
        public int Interval
        {
            get { return _timer.Interval; }
            set { _timer.Interval = value; }
        }

        int _nowCount=0;

        int _RunTimes = 0;
        /// <summary>
        /// 总共运行次数[为0则不计次数]
        /// </summary>
        public int RunTimes
        {
            get { return _RunTimes; }
            set
            {
                //重置当运行的次数
                _nowCount = 0;
                //关闭运行
                IsRunning = false;
                _RunTimes = value;
            }
        }
    }