Advertisement
programusy

Untitled

Oct 9th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 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. <Grid>
  6. <Ellipse Width="200" Height="200" Fill="LightGray"/>
  7. <Line X1="100" Y1="100" X2="100" Y2="30" Stroke="Black" StrokeThickness="2"/>
  8. <Line X1="100" Y1="100" X2="170" Y2="100" Stroke="Black" StrokeThickness="4"/>
  9. <TextBlock Text="12" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="95,0,0,0"/>
  10. <!-- Add other numbers (3, 6, 9) and clock hands as needed -->
  11. <TextBlock Text="3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,85,0,0"/>
  12. <TextBlock Text="6" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,95"/>
  13. <TextBlock Text="9" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="95,0,0,0"/>
  14. </Grid>
  15. </Window>
  16.  
  17.  
  18.  
  19. using System;
  20. using System.Windows;
  21. using System.Windows.Threading;
  22.  
  23. namespace YourNamespace
  24. {
  25. public partial class MainWindow : Window
  26. {
  27. private DispatcherTimer timer;
  28.  
  29. public MainWindow()
  30. {
  31. InitializeComponent();
  32. InitializeClock();
  33. }
  34.  
  35. private void InitializeClock()
  36. {
  37. // Create a timer to update the clock every second
  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. // Update the clock hands based on the current time
  47. DateTime currentTime = DateTime.Now;
  48. double hoursAngle = (currentTime.Hour % 12 + currentTime.Minute / 60.0) * 30;
  49. double minutesAngle = currentTime.Minute * 6;
  50.  
  51. // Rotate clock hands
  52. hourHandRotateTransform.Angle = hoursAngle;
  53. minuteHandRotateTransform.Angle = minutesAngle;
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement