示例#1
0
        private void getScrollInput()
        {
            bool hasRun = false;

            while (!hasRun)
            {// get input until 'enter' is detected
                //then execute selected method
                ConsoleKeyInfo userInput = Console.ReadKey();
                switch (userInput.Key)
                {
                case ConsoleKey.DownArrow:
                    if (currentScrollSelection < userMethods.Count - 1)
                    {
                        currentScrollSelection++;
                        displayMenu();
                    }
                    break;

                case ConsoleKey.UpArrow:
                    if (currentScrollSelection > 0)
                    {
                        currentScrollSelection--;
                        displayMenu();
                    }
                    break;

                case ConsoleKey.Enter:
                    choiceDelegate selection = userMethods[currentScrollSelection];
                    hasRunList[currentScrollSelection] = selection();
                    hasRun = true;
                    break;
                }
            }
        }
示例#2
0
 public void addMethod(choiceDelegate userMethod, string label) // userMethod must match delegate signature
 {
     if (type == 0)
     {
         throw new Exception("Cannot add methods to TextDisplay type menus.");
     }
     choiceLabel[assignedChoices] = label;
     if (type == 3)
     {
         findScrollMenuWidth(label);
     }
     assignedChoices++;
     hasRunList.Add(false);
     userMethods.Add(userMethod);
 }
示例#3
0
        private void getIntInput() // gets input and converts to int
        {
            try
            {
                int input;
                switch (type)
                {
                case 0:
                    input = Convert.ToInt16(Console.ReadLine());
                    break;

                case 1:
                    while (true)
                    {
                        input = Convert.ToInt16(Console.ReadLine());
                        if (input < userMethods.Count)    //prevent invalid selections
                        {
                            break;
                        }
                        // Console.Clear();  // UNNECCESARY?
                        // displayMenu();   //
                    }
                    choiceDelegate Choice = userMethods[input];
                    Console.Clear();
                    currentScrollSelection = input;     // for external retrieval
                    hasRunList[input]      = Choice();
                    break;

                case 2:
                    getStringInput();
                    break;
                }
            }
            catch (System.FormatException)
            {
                runMenu();
            }
        }