public void TestOnLostFocusWithInvalidInput()
        {
            currencyTextBox.Focus();
            string text = "abc.123";

            currencyTextBox.Text = text;
            FocusManager.SetFocusedElement(FocusManager.GetFocusScope(currencyTextBox), null);
            Keyboard.ClearFocus();
            Assert.AreEqual(text, currencyTextBox.Text);
        }
Пример #2
0
        }//end CurrencyTextBox_TextChanged

        /// <summary>
        /// This method starts off by determining if the entered number in the CurrencyTextBox
        /// is a number. If not, a message box is shown, telling them what is wrong, then clears the CurrencyTextBox
        /// and focuses it for the user and disables the button.
        /// If it is a number, it saves the number into original money.
        /// The program then grabs the selected indexs for the originalCurrencyComboBox and
        /// newCurrencyComboBox. These values are then passed through a method in the
        /// Currency_Exchange_Class which converts the currency the user has chosen.
        /// The wanted currency enum name is passed into the wantType label and displayed for the user.
        /// The converted money is then passed into the ConvertedCurrencyTextBox to be displayed for the user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void equalsButton_Click(object sender, EventArgs e)
        {
            int originalType, newType;

            double originalMoney, newMoney;

            if (!double.TryParse(CurrencyTextBox.Text, out originalMoney))
            {
                if (originalMoney < 1)
                {
                    MessageBox.Show("Please only use numbers");
                    CurrencyTextBox.Text = "";
                    CurrencyTextBox.Focus();

                    equalsButton.Enabled = false;
                }
                else
                {
                    originalType  = originalCurrencyComboBox.SelectedIndex;
                    newType       = newCurrencyComboBox.SelectedIndex;
                    originalMoney = double.Parse(CurrencyTextBox.Text);

                    newMoney = Currency_Exchange_Class.conversion(originalType, newType, originalMoney);

                    Currencies newCountry = (Currencies)newType;

                    wantType.Text = newCountry.ToString();


                    ConvertedCurrencyTextBox.Enabled = true;
                    ConvertedCurrencyTextBox.Text    = newMoney.ToString();
                    ConvertedCurrencyTextBox.Enabled = false;

                    CurrencyTextBox.Enabled           = false;
                    AnotherConversionGroupBox.Visible = true;
                }
            }
            else
            {
                MessageBox.Show("Please use a number greater than 0");
                CurrencyTextBox.Text = "";
                CurrencyTextBox.Focus();

                equalsButton.Enabled = false;
            }
        }// end equalsButton_Click