Example #1
0
        private void DeleteSelected()
        {
            var leftmost = Math.Min(_cursorIndex, _selectionOrigin);
            var range    = Math.Abs(_cursorIndex - _selectionOrigin);

            DisplayString    = DisplayString.Remove(leftmost, Math.Min(range, DisplayString.Length - leftmost));
            _cursorIndex     = leftmost;
            _selectionActive = false;
            AlignTextAndCursor();
        }
Example #2
0
 public void TrimZeroes()
 {
     if (DisplayString.Contains(","))
     {
         while (DisplayString.EndsWith("0"))
         {
             DisplayString = DisplayString.Remove(DisplayString.Length - 1);
         }
     }
     if (DisplayString.EndsWith(","))
     {
         DisplayString = DisplayString.Remove(DisplayString.Length - 1);
     }
 }
Example #3
0
        public bool Guess(char guess)
        {
            bool foundALetter = false;

            for (int i = 0; i < hiddenString.Length; i++)
            {
                if (hiddenString[i] == guess)
                {
                    DisplayString = DisplayString.Remove(i, 1);
                    DisplayString = DisplayString.Insert(i, guess.ToString());
                    foundALetter  = true;
                }
            }
            return(foundALetter);
        }
Example #4
0
 public void Delete()
 {
     if (_selectionActive)
     {
         DeleteSelected();
     }
     else
     {
         if (_cursorIndex == DisplayString.Length)
         {
             return;
         }
         DisplayString = DisplayString.Remove(_cursorIndex, 1);
     }
     ClampCursor();
 }
Example #5
0
 public void Backspace()
 {
     if (_selectionActive)
     {
         DeleteSelected();
     }
     else
     {
         if (_cursorIndex == 0)
         {
             return;
         }
         DisplayString = DisplayString.Remove(_cursorIndex - 1, 1);
         _cursorIndex--;
     }
     ClampCursor();
 }
Example #6
0
        // Нажатие оперирующих клавиш
        private void ButtonOp_Click(object sender, RoutedEventArgs e)
        {
            switch ((sender as Button).Name)
            {
            case "btBack":                                                          // "<--"
                if (!String.IsNullOrEmpty(DisplayString))
                {
                    DisplayString = DisplayString.Remove(DisplayString.Length - 1);
                    if (DisplayString == "-")
                    {
                        DisplayString = "";
                    }
                }
                UpdateDisplayString();
                break;

            case "btC":                                                             // "C"
                AllCleare();
                break;

            case "btCE":                                                            // "CE"
                LastOperation = Operation.None;
                DisplayString = LastValue;
                UpdateDisplayString();
                break;

            case "btPM":                                                            // "+/-"
                if (String.IsNullOrEmpty(DisplayString))
                {
                    return;
                }
                if (DisplayString[0] == '-')
                {
                    DisplayString = DisplayString.Replace("-", "");
                }
                else
                {
                    DisplayString = DisplayString.Insert(0, "-");
                }
                UpdateDisplayString();
                break;

            case "btSqrt":                                                          // "Sqrt"
                LastOperation = Operation.Sqrt;
                LastValue     = DisplayString;
                Calculate();
                LastValue     = DisplayString;
                LastOperation = Operation.None;
                isCalculate   = false;
                isClearString = true;
                break;

            case "btPercent":                                                       // "%"
                if (isCalculate)
                {
                    Calculate();
                    LastOperation = Operation.Percent;
                    break;
                }
                LastOperation = Operation.Percent;
                break;

            case "btOneOver":                                                       // "1/x"
                LastOperation = Operation.OneX;
                LastValue     = DisplayString;
                Calculate();
                LastValue     = DisplayString;
                LastOperation = Operation.None;
                isCalculate   = false;
                isClearString = true;
                break;

            case "btDevide":                                                        // "/"
                isClearString = true;
                if (isCalculate)
                {
                    Calculate();
                    LastOperation = Operation.Devide;
                    break;
                }
                LastOperation = Operation.Devide;
                TempValue     = "";
                break;

            case "btMultiply":                                                      // ""*
                isClearString = true;
                if (isCalculate)
                {
                    Calculate();
                    LastOperation = Operation.Multiply;
                    break;
                }
                LastOperation = Operation.Multiply;
                TempValue     = "";
                break;

            case "btMinus":                                                         // "-"
                isClearString = true;
                if (isCalculate)
                {
                    Calculate();
                    LastOperation = Operation.Minus;
                    break;
                }
                LastOperation = Operation.Minus;
                TempValue     = "";
                break;

            case "btPlus":                                                          // "+"
                isClearString = true;
                if (isCalculate)
                {
                    Calculate();
                    LastOperation = Operation.Plus;
                    break;
                }
                LastOperation = Operation.Plus;
                TempValue     = "";
                break;

            case "btEqual":                                                         // "="
                isClearString = true;
                if (isCalculate)
                {
                    TempValue = DisplayString;
                    Calculate();
                    AddDigit(DisplayString);
                    isCalculate   = false;
                    isClearString = false;
                    DisplayString = "";
                    break;
                }
                else if (LastOperation != Operation.None)
                {
                    if (!String.IsNullOrEmpty(DisplayString))
                    {
                        if (String.IsNullOrEmpty(TempValue))
                        {
                            TempValue = DisplayString;
                        }
                        AddDigit(DisplayString);
                    }
                    DisplayString = TempValue;
                    Calculate();
                    break;
                }
                break;

            case "btMemClear":                                                      // "MC"
                Memory = 0.0;
                break;

            case "btMemRead":                                                       // "MR"
                DisplayString = Memory.ToString();
                UpdateDisplayString();
                break;

            case "btMemSave":                                                       // "MS"
                if (ValidateString(DisplayString))
                {
                    Memory        = StringToDigit(DisplayString);
                    DisplayString = "";
                }
                break;

            case "btMemPlus":                                                        // "M+"
                if (ValidateString(DisplayString))
                {
                    Memory += StringToDigit(DisplayString);
                }
                break;

            case "btMemMinus":                                                      // "M-"
                if (ValidateString(DisplayString))
                {
                    Memory -= StringToDigit(DisplayString);
                }
                break;
            }
        }