Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="YourNamespace.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Clock App" Height="300" Width="300">
- <Canvas>
- <Ellipse Width="200" Height="200" Fill="LightGray" Canvas.Left="50" Canvas.Top="50"/>
- <Line x:Name="hourHand" X1="150" Y1="150" X2="150" Y2="100" Stroke="Black" StrokeThickness="6"/>
- <Line x:Name="minuteHand" X1="150" Y1="150" X2="150" Y2="70" Stroke="Black" StrokeThickness="4"/>
- <Line X1="150" Y1="150" X2="150" Y2="30" Stroke="Black" StrokeThickness="2"/>
- <TextBlock Text="12" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="145,60,0,0"/>
- <TextBlock Text="3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="85,145,0,0"/>
- <TextBlock Text="6" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="145,200,0,0"/>
- <TextBlock Text="9" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="200,145,0,0"/>
- </Canvas>
- </Window>
- using System;
- using System.Windows;
- using System.Windows.Media;
- using System.Windows.Threading;
- namespace YourNamespace
- {
- public partial class MainWindow : Window
- {
- private DispatcherTimer timer;
- public MainWindow()
- {
- InitializeComponent();
- InitializeClock();
- }
- private void InitializeClock()
- {
- timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- DateTime currentTime = DateTime.Now;
- double hoursAngle = (currentTime.Hour % 12 + currentTime.Minute / 60.0) * 30;
- double minutesAngle = currentTime.Minute * 6;
- hourHand.RenderTransform = new RotateTransform(hoursAngle, 150, 150);
- minuteHand.RenderTransform = new RotateTransform(minutesAngle, 150, 150);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement