SIGN UP MEMBER LOGIN:    
ARTICLE

Digital Watch In C#

Posted by Maheswara Rao Articles | GDI+ & Graphics June 04, 2001
GDI+ sample example shows you how to create a Digital Watch.
Reader Level:
Download Files:
 

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.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor