Advertisement
LostProphet

ArduinoMenu

Sep 25th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ArduinoMenu
  4. {
  5.     class Program
  6.     {
  7.         private static char arrow = (char)16;
  8.  
  9.         private static string[] menuItems = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" };
  10.         private static int maxItems = 5;
  11.         private static int currentLine = 0;
  12.  
  13.         private static bool exit = false;
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             while (!exit)
  18.             {
  19.                 Console.Clear();
  20.  
  21.                 for (int i = 0; i < maxItems; i++)
  22.                 {
  23.                     string currentMenuItem = menuItems[i];
  24.  
  25.                     if (i == currentLine)
  26.                         Console.WriteLine(arrow + currentMenuItem);
  27.                     else
  28.                         Console.WriteLine(" " + currentMenuItem);
  29.                 }
  30.  
  31.                 var key = Console.ReadKey().Key;
  32.  
  33.                 if (key == ConsoleKey.UpArrow && currentLine > 0)
  34.                 {
  35.                     currentLine--;
  36.                 }
  37.                 else if (key == ConsoleKey.DownArrow && currentLine < maxItems - 1)
  38.                 {
  39.                     currentLine++;
  40.                 }
  41.  
  42.                 if (key == ConsoleKey.Enter)
  43.                 {
  44.                     Console.Title = "You selected: " + menuItems[currentLine];
  45.                 }
  46.  
  47.                 if (key == ConsoleKey.Escape)
  48.                 {
  49.                     exit = true;
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement