Click here to Skip to main content
13,345,744 members (51,406 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 3 Mar 2005

Three Zone World Clock

, 3 Mar 2005
Rate this:
Please Sign up or sign in to vote.
A three time zone world clock

Sample Image - maximum width is 600 pixels


This article demonstrates how an irregular, skinnable world clock can be created and how application settings can be persisted using XML. The clock has been quite handy for working out who's awake and at their desk on a development project that spans multiple time zones.


This Three Zone World Clock was inspired by the article by Iulian Serban called How to build a Clock control. I have used a stripped down version of Iulian Serban's clock painting code and added logic for dealing with three clocks, handling transparency and the loading and saving of settings.

Using the code

I found when I started experimenting with transparent bitmaps on forms that there are a myriad ways of stuffing up transparency. After many searches and experiments I wrote this routine which seems to handle the transparency correctly. The routine loads a named skin file up from the application directory and then sets this as the background image for the form. Amazingly without the g.Clear statements subsequent bitmaps would be layered one on top of another - this was certainly a suprise feature for me!

private void SetSkin(string skinName, bool initializing)
      //Keep the new skin name in the application settings object<BR>      m_appSettings.SkinFile = skinName;<BR>
      //Find the application directory and then the full skin path<BR>      string appPath = Path.GetDirectoryName(Application.ExecutablePath);<BR>      string skinPath = appPath + "\\" + skinName;

      //Load skin if it exists
            Bitmap skinBmp = (Bitmap)Bitmap.FromFile(skinPath);

            //Clear form background to prevent overlays
                  Graphics g = this.CreateGraphics();

            //Apply transparency to the bitmap

            //Set the background image of the form
            BackgroundImage = skinBmp;

            //Apply transparency to the Form
            TransparencyKey = skinBmp.GetPixel(1,1);

            //Get the form to refresh

Persisting the Application State to XML

An XML file seemed to be the obvious choice for storing the application settings. The XML serializer was used to persist an AppSettings object containing three ClockSettings objects. Once the settings object model has been created, the code to save and load settings is pleasingly minimal. One pitfall I came across when using the XML serializer is that you must include default constructors for the classes being persisted, even if these default constructors serve no apparent purpose they have to be there or you get a lovely System.InvalidOperationException

private void SaveSettings()
      string appPath = Path.GetDirectoryName(Application.ExecutablePath);
      m_appSettings.Save(appPath + "\\settings.xml");
      m_saved = true;

Future Enhancements

Dave has been busy suggesting enhancements I could make, but heck I want my lunchtimes back so here is a list of "nice to have" things that I probably will not get time to code...

  • More clocks - would be nice if there were a configurable number of clocks (adding clocks is relatively easy but its making them look nice that's the tricky bit). At the moment the code is hardwired to three clocks, but I think I've left the door half open to add more.
  • An editor for setting up clock names and times - I agree that hacking the XML is not very nice!
  • Deployment from the top of the screen - not sure what Dave's getting at here but it has something to do with the clocks sliding down like a roller blind from the top of the screen. Hmmm.
  • AM/PM indicator. Like all true analog clocks, my clocks currently give absolutely no clue as to whether its day or night.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Bill Hoyland
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWere you able to develop another version in using ajax? Pin
smileoftushar3-Dec-09 6:52
membersmileoftushar3-Dec-09 6:52 
GeneralGreat!! Pin
Tonchi14-Mar-05 12:18
memberTonchi14-Mar-05 12:18 
QuestionBeerse? Pin
Patje3-Mar-05 22:20
memberPatje3-Mar-05 22:20 
AnswerRe: Beerse? Pin
billhoyland10-Mar-05 4:22
memberbillhoyland10-Mar-05 4:22 
GeneralRe: Beerse? Pin
Patje10-Mar-05 6:31
memberPatje10-Mar-05 6:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 3 Mar 2005
Article Copyright 2005 by Bill Hoyland
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid