public void AddString(string text) { if (_selectionActive) { DeleteSelected(); } DisplayString = DisplayString.Insert(_cursorIndex, text); DisplayString = DisplayString.Substring(0, Math.Min(2500, DisplayString.Length)); _cursorIndex += text.Length; ClampCursor(); }
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); }
// Нажатие оперирующих клавиш 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; } }