Advertisement
programusy

Untitled

Oct 9th, 2023
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <Window x:Class="YourNamespace.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="Clock App" Height="300" Width="300">
  5. <Canvas>
  6. <Ellipse Width="200" Height="200" Fill="LightGray" Canvas.Left="50" Canvas.Top="50"/>
  7. <Line x:Name="hourHand" X1="150" Y1="150" X2="150" Y2="100" Stroke="Black" StrokeThickness="6"/>
  8. <Line x:Name="minuteHand" X1="150" Y1="150" X2="150" Y2="70" Stroke="Black" StrokeThickness="4"/>
  9. <Line X1="150" Y1="150" X2="150" Y2="30" Stroke="Black" StrokeThickness="2"/>
  10. <TextBlock Text="12" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="145,60,0,0"/>
  11. <TextBlock Text="3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="85,145,0,0"/>
  12. <TextBlock Text="6" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="145,200,0,0"/>
  13. <TextBlock Text="9" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="200,145,0,0"/>
  14. </Canvas>
  15. </Window>
  16.  
  17.  
  18.  
  19. using System;
  20. using System.Windows;
  21. using System.Windows.Media;
  22. using System.Windows.Threading;
  23.  
  24. namespace YourNamespace
  25. {
  26. public partial class MainWindow : Window
  27. {
  28. private DispatcherTimer timer;
  29.  
  30. public MainWindow()
  31. {
  32. InitializeComponent();
  33. InitializeClock();
  34. }
  35.  
  36. private void InitializeClock()
  37. {
  38. timer = new DispatcherTimer();
  39. timer.Interval = TimeSpan.FromSeconds(1);
  40. timer.Tick += Timer_Tick;
  41. timer.Start();
  42. }
  43.  
  44. private void Timer_Tick(object sender, EventArgs e)
  45. {
  46. DateTime currentTime = DateTime.Now;
  47. double hoursAngle = (currentTime.Hour % 12 + currentTime.Minute / 60.0) * 30;
  48. double minutesAngle = currentTime.Minute * 6;
  49.  
  50. hourHand.RenderTransform = new RotateTransform(hoursAngle, 150, 150);
  51. minuteHand.RenderTransform = new RotateTransform(minutesAngle, 150, 150);
  52. }
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement