DonXML AnalogClock ' Developed using VB.NET v5.0
namespace ClockExample
' This will be used as Style for the hours
private UI TextHour as TextArea
FontWeight="Normal"
FontSize="15"
Foreground="#00F7D6"
End
' This is the actual clock layout
private UI ClockCanvas as Canvas(210,210)
' The Clock Frame
Ellipse(100,100,98,98)
Stroke="Black
StrokeThickness="1"
Fill.LinearGradientBrush.GradientStops.GradientStopCollection
GradientStop Color="silver" Offset="0.05"
GradientStop Color="#333333" Offset="0.95"
End
End
Ellipse(100,100,85,85)
Stroke="Black"
StrokeThickness="1"
Fill.LinearGradientBrush.GradientStops.GradientStopCollection
GradientStop Color="#333333" Offset="0.05" End
GradientStop Color="silver" Offset="0.95" End
End
End
' The Shadow
Ellipse(108,108,98,98)
Stroke="#FFFFFF00"
StrokeThickness="0"
Fill.SolidColorBrush Color="Black" Opacity="0.3" End
End
' The Clock Face
Ellipse(100,100,80,80)
Stroke="#666666"
StrokeThickness="1"
Fill.SolidColorBrush.Color="Black"
End
' The Hours
TextHour( 32,130) Text="1" End
TextHour( 57,154) Text="2" End
TextHour( 92,165) Text="3" End
TextHour(130,155) Text="4" End
TextHour(152,130) Text="5" End
TextHour(161, 96) Text="6" End
TextHour(152, 62) Text="7" End
TextHour(130, 37) Text="8" End
TextHour( 92, 27) Text="9" End
TextHour( 57, 34) Text="10"End
TextHour( 32, 58) Text="11"End
TextHour( 23, 92) Text="12"End
' The Hands
hours:TransformDecorator
AffectsLayout="False"
Transform.TransformCollection
RotateTransform Center="0,0" Angle="0" End
RotateTransform Center="0,0"
AngleAnimations.DoubleAnimation From="0" To="360" Duration="43200" RepeatDuration="Indefinite" End
End
TranslateTransform X="100" Y="100" End
End
Path Data="M -2.5,0 h 5 v -40 h -5 z" Fill="#00F7D6" Stroke="black" StrokeThickness="0.1" End
End
minutes:TransformDecorator
AffectsLayout="False"
Transform.TransformCollection
RotateTransform Center="0,0" Angle="0" End
RotateTransform Center="0,0"
AngleAnimations.DoubleAnimation From="0" To="360" Duration="3600" RepeatDuration="Indefinite" End
End
TranslateTransform X="100" Y="100" End
End
Path Data="M -2,0 h 4 v -65 h -4 z" Fill="#00F7D6" Stroke="black" StrokeThickness="0.1" End
End
seconds:TransformDecorator
AffectsLayout="False"
Transform.TransformCollection
RotateTransform Center="0,0" Angle="0" End
RotateTransform Center="0,0"
AngleAnimations.DoubleAnimation From="0" To="360" Duration="60" RepeatDuration="Indefinite" End
End
TranslateTransform X="100" Y="100" End
End
Path Data="M -1,0 h 2 v -70 h -2 z" Fill="red" Stroke="black" StrokeThickness="0.1" End
End
' The Center Disk
Ellipse(100,100,8,8)
Stroke="#00F7D6"
StrokeThickness="1"
Fill.SolidColorBrush.Color="Black"
End
End
' The class inherits from the UI
public class AnalogClock Inherits ClockCanvas
' The OnLoaded handler can be run automatically when the class is loaded.
private Sub OnLoaded(object sender, EventArgs e)
' Autocasting ON for better readability. See VB.NET v5.0 manual
CurrentDateTime = DateTime.Now
CurrentSecond = CurrentDateTime.Second
CurrentMinute = CurrentDateTime.Minute + (CurrentSecond / 60)
CurrentHour = CurrentDateTime.Hour + (CurrentMinute / 60)
SecondsTransforms = seconds.Transform
SecondsIntitalRotation = SecondsTransforms[0]
SecondsIntitalRotation.Angle = CurrentSecond * 6
MinutesTransforms = minutes.Transform
MinutesIntitalRotation = MinutesTransforms[0]
MinutesIntitalRotation.Angle = CurrentMinute * 6
HoursTransforms = hours.Transform
HoursIntitalRotation = HoursTransforms[0]
HoursIntitalRotation.Angle = CurrentHour * 30
End
End
End
' End of code