//Show this menu to the screen public void Show() { InitScreen(); //Remember current background/text color var currentBgColor = Console.BackgroundColor; var currentTxtColor = Console.ForegroundColor; //Keep in this menu until isFinished = true while (!isFinished) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; ConsoleFunctions.writeToCenter($"({selectedOption}) {_MenuOptions[selectedOption-1].ToString()}", 4 + selectedOption - 1); Console.ForegroundColor = currentTxtColor; Console.BackgroundColor = currentBgColor; //Read user input var pressedKey = Console.ReadKey(); switch (pressedKey.Key) { //Options are printed from top to bottom case ConsoleKey.UpArrow: if (!(selectedOption == 1)) { selectedOption--; } break; case ConsoleKey.DownArrow: if (!(selectedOption == _MenuOptions.Length)) { selectedOption++; } break; //Raise OptionSelected event with SelectedOption case ConsoleKey.Enter: OptionSelected.Invoke(this, selectedOption); InitScreen(); //Reinit the screen after returning to this menu break; //Exit Menu case ConsoleKey.Backspace: isFinished = true; break; } //draw all Options again for (int i = 0; i < _MenuOptions.Length; i++) { ConsoleFunctions.writeToCenter($"({i+1}) {_MenuOptions[i].ToString()}", 4 + i); } } }
public void Show(int?page = 1) //Display this Journal Page (Entry) { bool finished = false; //Temp while (!finished) { Console.Clear(); //Draw blocks ConsoleFunctions.writeToCenter($"= Journal Entry {journal.EntryId} =", 0); ConsoleFunctions.drawRectangle(8, (int)(Console.BufferWidth / 4), 0, 1); ConsoleFunctions.drawRectangle(8, (int)(Console.BufferWidth / 4), 0, 9); ConsoleFunctions.drawRectangle(16, (int)(Console.BufferWidth * 3 / 4), (int)(Console.BufferWidth / 4), 1); //draw content ConsoleFunctions.writeTO($"Author: {journal.Author}", 1, 3); ConsoleFunctions.writeTO($"Time: {journal.EntryTime.ToString()}", 1, 4); ConsoleFunctions.writeTO($"Location: {journal.Location}", 1, 5); //Write instructions ConsoleFunctions.writeTO($"Up key: Previous entry", 1, 10); ConsoleFunctions.writeTO($"Down key: Next entry", 1, 11); ConsoleFunctions.writeTO($"Left key: Previous page", 1, 12); ConsoleFunctions.writeTO($"Right key: Next page", 1, 13); ConsoleFunctions.writeTO($"Backspace: Return to menu", 1, 14); //Print report ConsoleFunctions.writeTO($"{journal.EntryTitle} ({page}/2)", (int)(Console.BufferWidth * 5 / 8) - (journal.EntryTitle.Length) / 2, 2); //I assume page starts with 1 and array starts with 0 right? (VB, get out.) var result = Regex.Matches(journal.Contents[(int)page - 1], @"(.{1," + ((Console.BufferWidth * 3 / 4) - 4) + @"})(?:\s|$)"); for (int i = 0; i < result.Count; i++) { ConsoleFunctions.writeTO(result[i].ToString(), (Console.BufferWidth / 4) + 2, i + 3); Thread.Sleep(30); } var pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.LeftArrow: page = 1; break; case ConsoleKey.RightArrow: page = 2; break; case ConsoleKey.Backspace: finished = true; break; } } }
//Init Menu screen private void InitScreen() { //Draw blocks and menu properties Console.Clear(); Console.WriteLine(); ConsoleFunctions.drawRectangle(15, Console.BufferWidth - 1, 0, 0); ConsoleFunctions.writeToCenter(_MenuTitle, 1); ConsoleFunctions.writeToCenter(_MenuSubTitle, 2); //Display all Options for (int i = 0; i < _MenuOptions.Length; i++) { Thread.Sleep(30); ConsoleFunctions.writeToCenter($"({i+1}) {_MenuOptions[i].ToString()}", 4 + i); } //Write instructions ConsoleFunctions.writeToCenter("[Up]:Previous [Down]:Next [Enter]:Select [Backspace]:Exit", 15); }