home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / The Timer and Time / SimpleClock / SimpleClock.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  40 lines

  1. //------------------------------------------
  2. // SimpleClock.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SimpleClock: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new SimpleClock());
  13.      }
  14.      public SimpleClock()
  15.      {
  16.           Text = "Simple Clock";
  17.           BackColor = SystemColors.Window;
  18.           ForeColor = SystemColors.WindowText;
  19.  
  20.           Timer timer    = new Timer();
  21.           timer.Tick    += new EventHandler(TimerOnTick);
  22.           timer.Interval = 1000;
  23.           timer.Start();
  24.      }
  25.      private void TimerOnTick(object sender, EventArgs ea)
  26.      {
  27.           Invalidate();
  28.      }
  29.      protected override void OnPaint(PaintEventArgs pea)
  30.      {
  31.           StringFormat strfmt  = new StringFormat();
  32.           strfmt.Alignment     = StringAlignment.Center;
  33.           strfmt.LineAlignment = StringAlignment.Center;
  34.  
  35.           pea.Graphics.DrawString(DateTime.Now.ToString("F"),
  36.                                   Font, new SolidBrush(ForeColor), 
  37.                                   ClientRectangle, strfmt);
  38.      }
  39. }
  40.