Beispiel #1
0
        public SolveAddView()
        {
            InitializeComponent();
            SolveTextBox            = this.FindControl <TextBox>("SolveTextBox");
            SolveTextBox.Text       = "00:00:00.00";
            SolveTextBox.CaretIndex = 6;
            SolveTextBox.CaretBrush = Avalonia.Media.Brushes.Yellow;
            SolveTextBox.AddHandler(TextInputEvent, PreviewTextInput, RoutingStrategies.Tunnel);
            SolveTextBox.AddHandler(KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel);

            CancelButton = this.Find <Button>("CancelButton");
#if DEBUG
            this.AttachDevTools();
#endif

            this.WhenActivated(disposableRegistration =>
            {
                this.BindCommand(
                    ViewModel,
                    viewModel => viewModel.CancelCommand,
                    view => view.CancelButton)
                .DisposeWith(disposableRegistration);

                ViewModel !.CancelCommand.Subscribe(_ => Close())
                .DisposeWith(disposableRegistration);
            });
        }
 private void SolveButton_Click(object sender, RoutedEventArgs e)
 {
     SolveTextBox.Clear();
     try
     {
         a = Double.Parse(aTextBox.Text);
         b = Double.Parse(bTextBox.Text);
         c = Double.Parse(cTextBox.Text) - Double.Parse(resultTextBox.Text);
     }
     catch (FormatException)
     {
         MessageBox.Show("Введите числа");
         return;
     }
     d = Math.Pow(b, 2) - 4 * a * c;
     SolveTextBox.Text += $"D = {b}² - 4 * {a} * {c} = {d}\n";
     if (d > 0)
     {
         x1 = (-b + Math.Sqrt(d)) / (2 * a);
         x2 = (-b - Math.Sqrt(d)) / (2 * a);
         SolveTextBox.Text += $"x1 = ({-b} + √{d})/(2 * {a}) = {x1}\n";
         SolveTextBox.Text += $"x2 = ({-b} - √{d})/(2 * {a}) = {x2}\n";
     }
     else if (d == 0)
     {
         x1 = x2 = -b / (2 * a);
         SolveTextBox.Text += $"x = {-b}/(2 * {a}) = {x1}\n";
     }
     else
     {
         SolveTextBox.Text += "Решений нет";
     }
 }
Beispiel #3
0
 protected override void OnOpened(EventArgs e)
 {
     base.OnOpened(e);
     SolveTextBox.Focus();
 }