![]() |
Platforms, Frameworks & Libraries »
Windows Presentation Foundation »
Controls
Beginner
License: The Code Project Open License (CPOL)
A WPF Digital ClockBy Derek BartramA WPF Digital Clock for displaying the current time, styled using RibbonStyleHandler |
C# (C# 3.0), Windows (Win2K, WinXP, Win2003, Vista), Win32, Win64, WPF, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||



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).
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.
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).
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).
ribboncontrol.aspx - The Ribbon Control library used in styling the control.
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
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 26 Apr 2008 Editor: |
Copyright 2008 by Derek Bartram Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |