Tools used : .NetFramework Beta 1, Editplus.IntroductionThis example displays current system time continuously.Classes and methods used in this example are
Graphics Class: Graphics Class encapsulates a GDI+ drawing surface. The FromHWND method is used to create a new instance of the Graphics class from a window handle. Clear method fills the entire drawing surface with the specified RGB color by using Color class. DrawString method draws a string using Font and SolidBrush classes. The DrawString method of graphics class displays the current time using DateTime.Now property.Timer Class : Implements the windows-based timer that raises an event at user-defined intervals. Interval property indicates the time interval to raise the Tick Event. Enabled property indicates whether to raises the Tick Event, if it is false Tick Event does not raised. Tick Event of Timer class raises for every one second and displays the system time.Source Code /* Author Mokhtar B Date 21st June, 2001 Company Adsoft Solutions Pvt. Ltd Application Type Windows Forms */using System;using System.WinForms;using System.Drawing;public class TimeTicker:Form{ private Graphics g;private Font DispFont;private string CDate; private SolidBrush MyBrush;// Constructorpublic TimeTicker(){InitializeComponents();}//InitializeComponents methodpublic void InitializeComponents(){ DispFont = new Font("Arial",35,FontStyle.Bold);MyBrush = new SolidBrush(Color.Red);CDate = DateTime.Now.ToString();g = Graphics.FromHWND(this.Handle);//Instantiating Timer ClassTimer aTimer = new Timer(); aTimer.Interval = 1000; // 1000 millisecondsaTimer.Enabled = true;aTimer.Tick += new EventHandler(OnTimer);//Setting Form Propertiesthis.Size = new Size(275, 150);this.Text = "Time Ticker";this.MaximizeBox = false;this.MinimizeBox = false;this.BorderStyle = FormBorderStyle.FixedSingle;this.StartPosition=FormStartPosition.CenterScreen;//Setting Form Icon through Icon Classthis.Icon = new Icon("clock.ico"); }protected override void OnPaint(PaintEventArgs e){g.DrawString(CDate.Substring(11) , DispFont,MyBrush,30,30);}//Timer Eventprotected void OnTimer(object source, EventArgs e){ CDate = DateTime.Now.ToString();g.Clear(Color.FromARGB(216,208,200));g.DrawString(CDate.Substring(11) , DispFont,MyBrush,30,30);}public static void Main(){Application.Run(new TimeTicker()); } }Compilationcsc /t:winexe /r:System.dll /r:System.WinForms.dll /r:System.Drawing.dll /r:Microsoft.Win32.Interop.dll TimeTicker.cs
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: