Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Menu
- {
- private Dictionary<int, string> list;
- public NoweMenu(Dictionary<int, string> opcje_wyboru) => list = opcje_wyboru;
- private void Print(int selected = 1)
- {
- Console.Clear();
- foreach (var item in list)
- {
- if (selected == item.Key)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("> ");
- Console.ResetColor();
- }
- else Console.Write(" ");
- Console.WriteLine(item.Key.ToString() + ". " + item.Value);
- }
- }
- public int Get()
- {
- int selected = 1;
- bool done = true;
- ConsoleKey key;
- while(done)
- {
- Print(selected);
- key = Console.ReadKey().Key;
- if (key == ConsoleKey.UpArrow)
- {
- if (selected == 1) selected = list.Count;
- else selected--;
- }
- else if (key == ConsoleKey.DownArrow)
- {
- if (selected == list.Count) selected = 1;
- else selected++;
- }
- else if (key == ConsoleKey.Enter) done = false;
- }
- return selected;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement