private void Delete() { if (CurrentDisplayLineLength == 0 & TextBoxType != TextBoxType.Multiline) { return; } if (CursorLeft != CurrentDisplayLineLength) { var line = CurrentDisplayLine; // remove one character from the list of characters CurrentDisplayLine = CurrentDisplayLine.Remove(CursorLeft, 1); } else { if (CurrentDisplayLineIndex < DisplayLines.Count) { DisplayLines.RemoveAt(CurrentDisplayLineIndex); } } // redraw and repaint DrawText(); Paint(); }
private void Backspace() { if (CurrentDisplayLineLength == 0) { return; } // remove one character from the list of characters if (CursorLeft == CurrentDisplayLineLength) { CurrentDisplayLine = CurrentDisplayLine.LeftPart(CursorLeft - 1); } else { if (CursorLeft == 0) { if (DecrementCursorTop()) { MoveToEnd(); var nextLine = DisplayLines[CurrentDisplayLineIndex + 1]; var newLine = CurrentDisplayLine.LeftPart(CursorLeft - 1); //DisplayLines.RemoveAt(CurrentDisplayLineIndex + 1); DisplayLines[CurrentDisplayLineIndex + 1] = string.Empty; CurrentDisplayLine = newLine + nextLine; } } else { CurrentDisplayLine = CurrentDisplayLine.Substring(0, CursorLeft - 1) + CurrentDisplayLine.Substring(CursorLeft, CurrentDisplayLine.Length - CursorLeft); } } // move the cursor to the left by one character MoveCursorLeft(); // redraw and repaint DrawText(); Paint(); }
private void ProcessKey(ConsoleKeyInfo info) { if ((CursorLeft < ClientWidth & Text.Length < MaxLength) || (CursorLeft < ClientWidth & MaxLength == 0)) { var keyValue = info.KeyChar.ToString(); // at the end of the line so add the character if (CursorLeft == CurrentDisplayLineLength) { if (info.Key == ConsoleKey.Enter) { DisplayLines.Insert(CurrentDisplayLineIndex + 1, string.Empty); } else { CurrentDisplayLine = CurrentDisplayLine + keyValue; } } else { var line = CurrentDisplayLine; if (Insert) { if (info.Key == ConsoleKey.Enter) { CurrentDisplayLine = line.LeftPart(CursorLeft); DisplayLines.Insert(CurrentDisplayLineIndex + 1, line.RightPart(CursorLeft)); } else { CurrentDisplayLine = CurrentDisplayLine.Insert(CursorLeft, keyValue); } } else { if (info.Key == ConsoleKey.Enter) { CurrentDisplayLine = line.LeftPart(CursorLeft); DisplayLines.Insert(CurrentDisplayLineIndex + 1, line.RightPart(CursorLeft + 1)); } else { CurrentDisplayLine = line.LeftPart(CursorLeft) + keyValue + line.RightPart(CursorLeft + 1); } } } if (info.Key == ConsoleKey.Enter) { IncrementCursorTop(); CursorLeft = 0; } else { CursorLeft++; if (CursorLeft >= ClientWidth) { if (TextBoxType == TextBoxType.Multiline) { CursorLeft = 0; if (CursorTop < ClientHeight) { CursorTop++; } } else { CursorLeft = ClientWidth; } } } SetCursorPosition(); // redraw and repaint DrawText(); Paint(); } }