Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ChangePageApp
- {
- class PageUI
- {
- string[] array;
- int pointer = 0;//указатель текущего пункта
- //конструктор в который передаешь пункты меню
- public PageUI(params string[] puncts)
- {
- array = new string[puncts.Length];
- for (int i = 0; i < puncts.Length; i++)
- {
- array[i] = puncts[i];
- }
- }
- //функция для отображения меню и переключения
- public int PageSwither()
- {
- ConsoleKeyInfo leverKey;
- //выводит в консоль все пункты меню, обновляется при каждом нажатии кнопок
- do
- {
- Console.Clear();
- for (int i = 0; i < array.Length; i++)
- {//если pointer указывает то выделяет
- if (pointer == i)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($">{array[i]}");
- Console.ResetColor();
- }
- //если pointer не указывает просто отображает
- else
- {
- Console.WriteLine(array[i]);
- }
- }
- //переключает пункты меню
- leverKey = Console.ReadKey();
- if (leverKey.Key == ConsoleKey.DownArrow)
- {
- pointer++;
- if (pointer == array.Length)
- {
- pointer = 0;
- }
- }
- else if (leverKey.Key == ConsoleKey.UpArrow)
- {
- pointer--;
- if (pointer < 0)
- {
- pointer = array.Length - 1;
- }
- }
- else { Console.WriteLine("wrong input");break; }
- } while (leverKey.Key != ConsoleKey.Enter);
- //возвращает пункт который выбрал
- return pointer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment