Digital Watch In C#


This sample example "Digital Watch In C#" uses GDI+ to create the watch.

using System;
using System.WinForms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
//Image class for storing images
private Image []image=new Bitmap[10];
private Image colon=null;
//this is timer class for each sec
Timer t=new Timer();
//storing images in to image objecte 
........
for(int x=0;x<10;x++)
image[x]=
new Bitmap(x+".gif");
colon=
new Bitmap("colon.gif");
//removing form boarder
this.BorderStyle=FormBorderStyle.None;
//form background
this.BackgroundImage=new Bitmap("back5.gif");
//for specified location on desktop
this.StartPosition=FormStartPosition.Manual;
this.DesktopLocation=new Point(400,0);
//in task bar hiding
this.ShowInTaskbar=false;
//display top most
this.TopMost=true;
//transparency form
this.Opacity=0.50;
//for timer event
t.Interval=1000;
t.Tick+=
new EventHandler(draw1);
t.Enabled=
true;
//override OnPaint method
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);
}
//repaint the form
public void draw1(object ob,EventArgs a)
{
this.Invalidate();
}
.........

This is Mahesh form India, in this world only one thing you never get it again that is TIME.

That is way you should know how much time you are spending with System. I developed small application using C#, if it is useful to you. I am a first guy in the world who feel very happy.


Similar Articles