Advertisement
youuw

Untitled

Nov 16th, 2022
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | Software | 0 0
  1. struct Menu
  2.         {
  3.             private Dictionary<int, string> list;
  4.             public NoweMenu(Dictionary<int, string> opcje_wyboru) => list = opcje_wyboru;
  5.  
  6.             private void Print(int selected = 1)
  7.             {
  8.                 Console.Clear();
  9.                 foreach (var item in list)
  10.                 {
  11.                     if (selected == item.Key)
  12.                     {
  13.                         Console.ForegroundColor = ConsoleColor.Red;
  14.                         Console.Write("> ");
  15.                         Console.ResetColor();
  16.                     }
  17.                     else Console.Write("  ");
  18.                     Console.WriteLine(item.Key.ToString() + ". " + item.Value);
  19.                 }
  20.             }
  21.             public int Get()
  22.             {
  23.                 int selected = 1;
  24.                 bool done = true;
  25.                 ConsoleKey key;
  26.                 while(done)
  27.                 {
  28.                     Print(selected);
  29.                     key = Console.ReadKey().Key;
  30.                     if (key == ConsoleKey.UpArrow)
  31.                     {
  32.                         if (selected == 1) selected = list.Count;
  33.                         else selected--;
  34.                     }
  35.                     else if (key == ConsoleKey.DownArrow)
  36.                     {
  37.                         if (selected == list.Count) selected = 1;
  38.                         else selected++;
  39.                     }
  40.                     else if (key == ConsoleKey.Enter) done = false;
  41.                 }
  42.                 return selected;
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement