Page1.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfApp1
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Page1.xaml
  19. /// </summary>
  20. public partial class Page1 : Page
  21. {
  22. public Page1()
  23. {
  24. InitializeComponent();
  25. }
  26. private void CalculateButton_Click(object sender, RoutedEventArgs e)
  27. {
  28. if (double.TryParse(AngleTextBox.Text, out double angle) &&
  29. double.TryParse(TimeTextBox.Text, out double time))
  30. {
  31. angle = angle * Math.PI / 180;
  32. double acceleration = 9.8 * Math.Sin(angle);
  33. double distance = 0.5 * acceleration * time * time;
  34. ResultLabel.Content = $"Пройденное расстояние: {distance} м";
  35. }
  36. else
  37. {
  38. MessageBox.Show("Пожалуйста, введите числовые значения.", "Ошибка ввода!", MessageBoxButton.OK, MessageBoxImage.Error);
  39. }
  40. }
  41. private void Button_Click(object sender, RoutedEventArgs e)
  42. {
  43. AngleTextBox.Text = string.Empty;
  44. TimeTextBox.Text = string.Empty;
  45. ResultLabel.Content = string.Empty;
  46. }
  47. }
  48. }