Click here to Skip to main content
Licence CPOL
First Posted 26 Apr 2008
Views 48,625
Downloads 2,909
Bookmarked 42 times

A WPF Digital Clock

A WPF Digital Clock for displaying the current time, styled using RibbonStyleHandler
1 vote, 8.3%
1
1 vote, 8.3%
2
3 votes, 25.0%
3
3 votes, 25.0%
4
4 votes, 33.3%
5
3.96/5 - 12 votes
1 removed
μ 3.75, σa 2.38 [?]

digitalclock1.jpg

digitalclock2.jpg

digitalclock3.jpg

Introduction

This article presents a digital clock written using C# .Net 3.5 and Windows Presentation Foundation (WPF), with a version supporting styling using the RibbonStyleHandler from the Ribbon Control Library (and hence allowing styling consistent with RibbonWindow applications).

Using the Code

This is VERY simple, to create a new clock window, make a new instance of DigitalClockWindow! To add a control to an existing window, use DigitalClockControl.

About the Code

The DigitalClock class is comprised of DigitalClockDots and DigitalClockElement. The DigitalClockDots class is a UIElement representing two dots to separate hours from minutes from seconds. DigitalClockElement represents the following states: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Hence the DigitalClock is a Grid of DigitalClockElement DigitalClockElement DigitalClockDots DigitalClockElement DigitalClockElement DigitalClockDots DigitalClockElement DigitalClockElement.

The DigitalClockControl and DigitalClockWindow classes contain a thread for updating the clock when AutoUpdate is set to true, otherwise the clock may be updated via the .CurrentTime property of DigitalClockControl.

DigitalClockControl contains three properties for styling, DigitBrush the Brush used to render the digits (0 to 9), DotBrush the Brush used to render the separating dots, and ClockBackground the background of the clock. DigitalClockDots contains a single property RenderBrush for setting the brush used to render the dots. DigitalClockElement contains a similar property RenderBrush for setting the brush used to render the graphic components. Furthermore it also contains a Value property for setting the value to display (in the range 0 to 9).

Ribbon Styled Clock

In version 1.0.0.1 RibbonClockControl and RibbonClockWindow have been added which inherit from DigitalClockControl and DigitalControlWindow respectively; they add automatic styling based on the RibbonStyleChanged event, and can be seen in use in the CIRIP project (a Computational Intelligent Railway Intervention Planner).

References

ribboncontrol.aspx - The Ribbon Control library used in styling the control.

History

Version 1.0.0.0 - Initial build

Version 1.0.0.1 - Separated Ribbon styling from clock.

Version 1.0.0.1 - Added AutoUpdate and CurrentTime properties to allow display of custom times

Version 1.0.0.1 - Added RibbonClockControl and Window with Ribbon styling

Version 1.0.0.1 - Refactored controls to allow resizing

Version 1.0.0.1 - Changed clock from Window to UserControl and added DigitalClockWindow

Version 1.0.0.1 - Fixed bug where update thread kept process alive

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Derek Bartram

Software Developer
Rail Research UK
United Kingdom United Kingdom

Member
I originally studied for a masters in engineering of software engineering at The University of Birmingham during 2000-2004, of which I received a 2:1. I continued at Birmingham University working with Civil Engineering and Rail Research UK where I am currently in my final year of a 3 year PhD project developing a Computational Intelligent Approach to Railway Intervention Planning. Although my work has a significant focus on railway engineering and associated practices much of my work is with data mining (on SQL Server 2008) and computational intelligence (CI) techniques. My key areas of expertise in CI are clustering algorithms (including Rival Penalised Competitive Learning) and evolutionary algorithms.
 
Outside of my formal work I enjoy testing the latest technologies such as .NET 3.5 and the many frameworks of which it comprises (mainly WPF). I have several projects on the go including a .NET and DirectX port of Quake 3 and many utility libraries. I also maintain an extensive website coded in Cold Fusion which is regularly updated; more information is available about me there.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralLicense terms Pinmembermjmeans21:14 18 Jan '11  
GeneralRe: License terms PinmemberDerek Bartram4:25 19 Jan '11  
GeneralStop update thread from control instead of from containing window PinmemberGeert Verbakel23:10 3 Mar '10  
NewsNew Version Released 1.0.0.1 PinmemberDerek Bartram3:56 1 May '08  
QuestionReferances PinmemberKing_kLAx1:39 27 Apr '08  
GeneralRe: Referances PinmemberDerek Bartram2:22 27 Apr '08  
GeneralA few other comments PinsupporterMarc Clifton10:32 26 Apr '08  
GeneralRe: A few other comments PinmemberDerek Bartram12:44 26 Apr '08  
GeneralRe: A few other comments PinmemberDerek Bartram12:47 26 Apr '08  
GeneralRe: A few other comments PinsupporterMarc Clifton12:48 26 Apr '08  
GeneralRe: A few other comments PinmemberDerek Bartram1:07 27 Apr '08  
GeneralRe: A few other comments PinsupporterMarc Clifton3:23 27 Apr '08  
QuestionWhere do I download the Ribbon Control Library? PinsupporterMarc Clifton10:15 26 Apr '08  
AnswerRe: Where do I download the Ribbon Control Library? PinmemberDerek Bartram12:37 26 Apr '08  
Thank you for pointing that out; it's now been referanced in the article.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.5.120210.1 | Last Updated 26 Apr 2008
Article Copyright 2008 by Derek Bartram
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid