Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: C#  |  size: 3.44 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Net;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Documents;
  6. using System.Windows.Ink;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. using System.Windows.Shapes;
  11. using System.ComponentModel;
  12. using System.Windows.Threading;
  13. namespace Reloj
  14. {
  15.  
  16.     public class TipoRelojChangedEventArgs : EventArgs
  17.     {
  18.         Reloj.TipoReloj nuevoTipoDeReloj;
  19.  
  20.             public Reloj.TipoReloj NuevoTipoDeReloj
  21.             {
  22.             get { return nuevoTipoDeReloj; }
  23.             set { nuevoTipoDeReloj = value; }
  24.             }
  25.        }
  26.     public class Reloj : INotifyPropertyChanged
  27.     {
  28.         public delegate void TipoRelojChangedEventHandler(object sender, TipoRelojChangedEventArgs e);
  29.         public enum TipoReloj
  30.         {
  31.             Analogico,
  32.             Digital
  33.         };
  34.        
  35.         TipoReloj tipoDeReloj = TipoReloj.Analogico;
  36.         public TipoReloj TipoDeReloj
  37.         {
  38.             get { return tipoDeReloj; }
  39.             set
  40.             {
  41.                 tipoDeReloj = value;
  42.                 TipoRelojChanged.Invoke(this, new TipoRelojChangedEventArgs() {NuevoTipoDeReloj = value });
  43.             }
  44.         }
  45.  
  46.         public event TipoRelojChangedEventHandler TipoRelojChanged;
  47.  
  48.         DispatcherTimer dispatcherTimer;
  49.         public Reloj()
  50.         {
  51.             dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
  52.             dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
  53.             dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
  54.             dispatcherTimer.Start();
  55.         }
  56.  
  57.         void dispatcherTimer_Tick(object sender, EventArgs e)
  58.         {
  59.             DateTime dt = DateTime.Now;
  60.             Segundo = dt.Second;
  61.             Minuto = dt.Minute;
  62.             Hora = dt.Hour;
  63.         }
  64.  
  65.         void OnPropertyChanged(string propertyName)
  66.         {
  67.             if (PropertyChanged != null)
  68.             {
  69.                 PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
  70.             }
  71.         }
  72.         int hora, minuto, segundo;
  73.        
  74.         public int Segundo
  75.         {
  76.             get { return segundo;}
  77.             set
  78.             {
  79.                 segundo = value;
  80.                 OnPropertyChanged("Segundo");
  81.                 OnPropertyChanged("SegundoAngulo");
  82.             }
  83.         }
  84.  
  85.         public int Minuto
  86.         {
  87.             get { return minuto; }
  88.             set
  89.             {
  90.                 minuto = value;
  91.                 OnPropertyChanged("Minuto");
  92.                 OnPropertyChanged("MinutoAngulo");
  93.             }
  94.         }
  95.         public int Hora
  96.         {
  97.             get { return hora; }
  98.             set
  99.             {
  100.                 hora = value;
  101.                 OnPropertyChanged("Hora");
  102.                 OnPropertyChanged("HoraAngulo");
  103.             }
  104.         }
  105.  
  106.         public event ProgressChangedEventHandler PropertyChanged;
  107.         public double HoraAngulo
  108.         {
  109.             get
  110.             {
  111.                 return (((float)Hora / 12) * 360 + Minuto / 2);
  112.             }
  113.         }
  114.         public double MinutoAngulo
  115.         {
  116.             get
  117.             {
  118.                 return (((float)Minuto) / 60) * 360;
  119.             }
  120.         }
  121.         public double SegundoAngulo
  122.         {
  123.             get
  124.             {
  125.                 return (((float)Segundo) * 360);
  126.             }
  127.         }
  128.     }
  129. }