Пример #1
0
        public static MenuChoice Menu(string[] choices, string title = "Make your choice")
        {
            var mc = new MenuChoice();

            mc.choices = choices;
            Console.Clear();
            for (int i = 0; i < choices.Length + 1; i++)
            {
                Console.Write("\r\n");
            }
            Console.WriteLine(title.DrawInConsoleBox());
            //var menu = new Menu(new string[] { "John", "Bill", "Janusz", "Grażyna", "1500", ":)" });
            var menu        = new MenuClass(choices);
            var menuPainter = new ConsoleMenuPainter(menu);

            var done = false;

            do
            {
                menuPainter.Paint(0, 0);

                var keyInfo = Console.ReadKey();

                switch (keyInfo.Key)
                {
                case ConsoleKey.UpArrow:
                    menu.MoveUp();
                    break;

                case ConsoleKey.DownArrow:
                    menu.MoveDown();
                    break;

                case ConsoleKey.Enter:
                    done = true;
                    break;
                }
            } while (!done);

            mc.choice_id = menu.SelectedIndex;
            mc.choice    = menu.SelectedOption;
            mc.used      = true;
            mc.title     = title;

            Console.ForegroundColor = ConsoleColor.Cyan;
            //Console.WriteLine("Selected option: " + (menu.SelectedOption ?? "(nothing)"));
            //Console.ReadKey();

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            //return menu.SelectedOption;
            return(mc);
        }
Пример #2
0
 public ConsoleMenuPainter(MenuClass menu)
 {
     this.menu = menu;
 }