Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Input;
- namespace consoleMenuNavigate
- {
- class Program
- {
- static string[] menu;
- static int index = 0;
- static void Main(string[] args)
- {
- Initialize();
- DrawMenu();
- while (true)
- {
- GetKeyboardState();
- DrawMenu();
- }
- }
- static void Initialize()
- {
- menu = new string[] { "1. menüpont", "2. menüpont", "3. menüpont", "4. menüpont", "5. menüpont" };
- // egyéb szükséges dolgok
- }
- static void GetKeyboardState()
- {
- ConsoleKeyInfo info = Console.ReadKey();
- if (info.Key == ConsoleKey.DownArrow)
- {
- if (index < menu.Length - 1)
- {
- index++;
- }
- }
- if (info.Key == ConsoleKey.UpArrow)
- {
- if (index > 0)
- {
- index--;
- }
- }
- if (info.Key == ConsoleKey.Enter)
- {
- enterMenu(index);
- }
- }
- static void DrawMenu()
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < menu.Length; i++)
- {
- if (i == index)
- {
- Console.BackgroundColor = ConsoleColor.Blue;
- Console.WriteLine(menu[i]);
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.Black;
- Console.WriteLine(menu[i]);
- }
- }
- Console.BackgroundColor = ConsoleColor.Black;
- }
- static void enterMenu(int index) // univerzalitás híján...
- {
- switch (index)
- {
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- default:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement