标题:有始以来最简单的Clock(C# Winform)
只看楼主
mkxzy
Rank: 2
等 级:论坛游民
帖 子:39
专家分:40
注 册:2007-3-26
结帖率:0
已结贴  问题点数:10 回复次数:1 
有始以来最简单的Clock(C# Winform)
//Clock
class Clock : INotifyPropertyChanged
    {
        private Timer timer = new Timer();
        private DateTime currentTime = DateTime.Now;

        public Clock()
        {
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            currentTime = DateTime.Now;
            PropertyChangedEventArgs arg = new PropertyChangedEventArgs("CurrentTime");
            OnPropertyChanged(arg);
        }

        protected void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }

        public DateTime CurrentTime
        {
            get { return currentTime; }
        }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

//调用

Clock clock = new Clock();
label1.DataBindings.Add("Text", clock, "CurrentTime", true);

大家觉得如何?
搜索更多相关主题的帖子: Winform Clock 
2009-12-02 23:44
kiska3088915
Rank: 2
等 级:论坛游民
帖 子:72
专家分:12
注 册:2009-11-7
得分:10 
不错不错,即使是这么简单的程序,也有值得我学习的东西~~~~顶了~~~··
2009-12-03 00:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-293750-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.644905 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved