Пример #1
0
        static ButtonInConsoleSetter[] SetControl(string name, KeyboardMenu <ButtonInConsole> menu, ConsolePrintMenu printer, string[] buttonsName, needOption[] buttonsOptions)
        {
            if (buttonsName.Length != buttonsOptions.Length)
            {
                throw new Exception();
            }
            var buttons = new ButtonInConsoleSetter[buttonsName.Length];

            for (int i = 0; i < buttons.Length; i++)
            {
                buttons[i] = new ButtonInConsoleSetter(printer.Width - 10, 1, printer, SignConsole.GetSignConsoles(buttonsName[i]));
                printer.Register((5, 8 + i * 2), buttons[i], buttons[i].GetCoordinates());
                menu.AddLastButton(buttons[i]);
                var option = buttonsOptions[i];
                buttons[i].IsPressed += () =>
                {
                    var newKey = Console.ReadKey(true);
                    KeyPress.Remove(name, KeyPress.GetKey(name, Keys[option]));
                    KeyPress.Reset(name, newKey.Key, Keys[option]);
                    setValue();
                };
            }
            setValue();
            void setValue()
            {
                for (int i = 0; i < buttons.Length; i++)
                {
                    buttons[i].Value = SignConsole.GetSignConsoles(KeyPress.GetKey(name, Keys[buttonsOptions[i]]).ToString());
                }
            }

            return(buttons);
        }