Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Digital Clock in C#
By Mahesh

Here is a an example of how to make a digital clock using C#. I have included the graphics, source code, and command line string (included as a file - comp.bat) in the zip file. I hope you enjoy!!

Download Digital Clock - archive29.zip

using System;
using System.WinForms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class h2:Form
{
 private Image []image=new Bitmap[10];
 private Image colon=null;
 Timer t=new Timer();
 Rectangle rec=new Rectangle(50,50,100,100);
 h2()
 {
  for(int x=0;x<10;x++)
  image[x]=new Bitmap(x+".gif");
  colon=new Bitmap("colon.gif");
  this.Size=new Size(350,50);
  this.BorderStyle=FormBorderStyle.None;
  this.BackgroundImage=new Bitmap("back5.gif");
  this.StartPosition=FormStartPosition.Manual;
  this.DesktopLocation=new Point(400,0);
  this.ShowInTaskbar=false;
  this.TopMost=true;
  this.Opacity=0.50;
  t.Interval=1000;
  t.Tick+=new EventHandler(draw1);
  t.Enabled=true;
 }
 protected override void OnPaint(PaintEventArgs a)
 {
  Graphics g=a.Graphics;
  int hh=DateTime.Now.Hour;
  int hh1=hh/10;
  int hh2=hh%10;
  g.DrawImage(image[hh1],0,1,40,40);
  g.DrawImage(image[hh2],40,1,40,40);
  g.DrawImage(colon,80,5,30,30);
  int mm=DateTime.Now.Minute;
  int mm1=mm/10;
  int mm2=mm%10;
  g.DrawImage(image[mm1],115,1,40,40);
  g.DrawImage(image[mm2],155,1,40,40);
  g.DrawImage(colon,195,5,30,30);
  int ss=DateTime.Now.Second;
  int ss1=ss/10;
  int ss2=ss%10;
  g.DrawImage(image[ss1],230,1,40,40);
  g.DrawImage(image[ss2],285,1,40,40);
 }
 public void draw1(object ob,EventArgs a)
 {
  this.Invalidate();
 }
 public static void Main()
 {
  Application.Run(new h2());
 }
}