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">
- <Grid>
- <Ellipse Width="200" Height="200" Fill="LightGray"/>
- <Line X1="100" Y1="100" X2="100" Y2="30" Stroke="Black" StrokeThickness="2"/>
- <Line X1="100" Y1="100" X2="170" Y2="100" Stroke="Black" StrokeThickness="4"/>
- <TextBlock Text="12" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="95,0,0,0"/>
- <!-- Add other numbers (3, 6, 9) and clock hands as needed -->
- <TextBlock Text="3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,85,0,0"/>
- <TextBlock Text="6" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,95"/>
- <TextBlock Text="9" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="95,0,0,0"/>
- </Grid>
- </Window>
- using System;
- using System.Windows;
- using System.Windows.Threading;
- namespace YourNamespace
- {
- public partial class MainWindow : Window
- {
- private DispatcherTimer timer;
- public MainWindow()
- {
- InitializeComponent();
- InitializeClock();
- }
- private void InitializeClock()
- {
- // Create a timer to update the clock every second
- timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- // Update the clock hands based on the current time
- DateTime currentTime = DateTime.Now;
- double hoursAngle = (currentTime.Hour % 12 + currentTime.Minute / 60.0) * 30;
- double minutesAngle = currentTime.Minute * 6;
- // Rotate clock hands
- hourHandRotateTransform.Angle = hoursAngle;
- minuteHandRotateTransform.Angle = minutesAngle;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement