All pastes #175017 Raw Edit

zeroflag

public text v1 · immutable
·published 2006-09-18 12:50 UTC
rendered paste body
	public partial class Clock : Label, IDisposable
	{
		System.Timers.Timer m_UpdateTimer = new System.Timers.Timer();

		public System.Timers.Timer UpdateTimer
		{
			get { return m_UpdateTimer; }
		}
		
		public Clock()
		{
			this.TimeUpdate();

			this.UpdateTimer.AutoReset = true;		// repeat...
			this.UpdateTimer.Interval = 200;		// update very 200ms... could be slower like 500 or 1000ms...
			this.UpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateTimer_Elapsed);
			this.UpdateTimer.Start();
		}

		void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
		{
			this.TimeUpdate();
		}

		protected virtual void TimeUpdate()
		{
			this.Text = DateTime.Now.ToLongTimeString();
		}

		void IDisposable.Dispose()
		{
			this.UpdateTimer.Stop();
		}

	}