Exemple #1
0
 private void ComboBoxRoundOrExact_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if ((!(DegreesRadiansBox == null)) && (double.TryParse(DegreesRadiansBox.Text, out double DegreesRadiansNumber)))
     {
         if (RadiansButton.IsChecked == true)
         {
             if (ComboBoxRoundOrExact.SelectedItem.ToString() == "System.Windows.Controls.ComboBoxItem: Rounded to Decimal")
             {
                 DegreesRadiansBox.Text   = Convert.ToString(DegreesRadiansNumber * Math.PI);
                 TextBlock_PiDisplay.Text = "";
             }
             else if (ComboBoxRoundOrExact.SelectedItem.ToString() == "System.Windows.Controls.ComboBoxItem: Exact, using Pi")
             {
                 DegreesRadiansBox.Text   = Convert.ToString(DegreesRadiansNumber / Math.PI);
                 TextBlock_PiDisplay.Text = "𝜋";
             }
             else
             {
                 DegreesRadiansBox.Text = ComboBoxRoundOrExact.SelectedItem.ToString();
             }
         }
     }
     else
     {
         if ((!(DegreesRadiansBox == null)))
         {
             ValidationError1 ValidationErrorWin = new ValidationError1();
             ValidationErrorWin.Show();
         }
     }
 }
Exemple #2
0
        private void ButtonOperator_Click(object sender, RoutedEventArgs e)
        {
            Button OperationButton = sender as Button;
            string Operation       = OperationButton.Name;


            if (double.TryParse(Operand2.Text, out double Operand2Num) && double.TryParse(Operand1.Text, out double Operand1Num))
            {
                switch (Operation)
                {
                case "ButtonAdd":
                    Answer.Text = Convert.ToString(Operand1Num + Operand2Num);
                    break;

                case "ButtonSubtract":
                    Answer.Text = Convert.ToString(Operand1Num - Operand2Num);
                    break;

                case "ButtonDivide":
                    if (Operand2Num == 0)
                    {
                        DivideByZeroError DivByZeroErrorWin = new DivideByZeroError();
                        DivByZeroErrorWin.Show();
                        Operand2.Focus();
                    }
                    else
                    {
                        Answer.Text = Convert.ToString(Operand1Num / Operand2Num);
                    }
                    break;

                case "ButtonMultiply":
                    Answer.Text = Convert.ToString(Operand1Num * Operand2Num);
                    break;

                default:
                    Answer.Text = "???";
                    break;
                }
            }
            else
            {
                ValidationError1 ValidationErrorWin = new ValidationError1();
                ValidationErrorWin.Show();
            }
        }