Exemple #1
0
        public static int DialogBox(byte Flag, params string[] SrcStringList)
        {
            if (SrcStringList == null)
            {
                return(0);
            }
            string TmpS      = "";
            int    MaxLength = 28
            , I         = 0
            , KeysCount = 0
            , Result    = 1;

            System.ConsoleKey KeyCode;
            string[]          KeysStr    = new   string[3];
            string[]          StringList = new   string[SrcStringList.Length + 3];
            for (I = 0; I < SrcStringList.Length; I++)
            {
                TmpS = SrcStringList[I];
                if (TmpS.Length > MaxLength)
                {
                    MaxLength = TmpS.Length;
                }
                StringList[I] = TmpS;
            }
            I                 = SrcStringList.Length;
            StringList[I]     = CCommon.RepStr("_", MaxLength);
            StringList[I + 1] = " ";
            StringList[I + 2] = " ";
            switch (Flag & 15)
            {
            case    DIALOG_BOX_OK: {
                KeysCount  = 1;
                KeysStr[0] = "[ Годится ]";
                break;
            }

            case    DIALOG_BOX_OK_: {
                KeysCount  = 1;
                KeysStr[0] = "[ ОК ]";
                break;
            }

            case    DIALOG_BOX_YES_NO: {
                KeysCount  = 2;
                KeysStr[0] = "[ Да ]";
                KeysStr[1] = "[ Нет ]";
                break;
            }

            case    DIALOG_BOX_YES_NO_: {
                KeysCount  = 2;
                KeysStr[0] = "[ Yes ]";
                KeysStr[1] = "[ No ]";
                break;
            }

            case    DIALOG_BOX_STAY_CANCEL: {
                KeysCount  = 2;
                KeysStr[0] = "[ Продолжить ]";
                KeysStr[1] = "[ Отмена ]";
                break;
            }

            case    DIALOG_BOX_STAY_CANCEL_: {
                KeysCount  = 2;
                KeysStr[0] = "[ Continue ]";
                KeysStr[1] = "[ Cancel ]";
                break;
            }

            case    DIALOG_BOX_RETRY_CANCEL: {
                KeysCount  = 2;
                KeysStr[0] = "[ Повторить ]";
                KeysStr[1] = "[ Отмена ]";
                break;
            }

            case    DIALOG_BOX_RETRY_CANCEL_: {
                KeysCount  = 2;
                KeysStr[0] = "";
                KeysStr[1] = "";
                break;
            }

            default: {
                KeysCount = 0;
                break;
            }
            }
            if (KeysCount == 0)
            {
                return(0);
            }
            for (I = 0; I < KeysCount; I++)
            {
                MaxLength -= (KeysStr[I].Length + 1);
            }
            MaxLength = MaxLength >> 1;
            bool SavedCursor = System.Console.CursorVisible;

            ShowBox(StringList);
            System.Console.CursorVisible = false;
            byte SavedColor = Color;

            do
            {
                System.Console.CursorLeft = Left + MaxLength + 1;
                System.Console.CursorTop  = Top + SrcStringList.Length + 2;
                for (I = 0; I < KeysCount; I++)
                {
                    if (Result == (I + 1))
                    {
                        Color = MenuColor;
                    }
                    else
                    {
                        Color = BoxColor;
                    }
                    System.Console.Write(KeysStr[I]);
                    Color = BoxColor;
                    System.Console.Write(" ");
                }
                KeyCode = ReadKey();
                if (KeysCount > 1)
                {
                    if ((KeyCode == CConsole.KEY_RIGHT) || (KeyCode == CConsole.KEY_DOWN) || (KeyCode == CConsole.KEY_6) || (KeyCode == CConsole.KEY_2))
                    {
                        Result++;
                    }
                    if ((KeyCode == CConsole.KEY_LEFT) || (KeyCode == CConsole.KEY_UP) || (KeyCode == CConsole.KEY_4) || (KeyCode == CConsole.KEY_8))
                    {
                        Result--;
                    }
                    if (Result == 0)
                    {
                        Result = KeysCount;
                    }
                    if (Result > KeysCount)
                    {
                        Result = 1;
                    }
                }
            } while ((KeyCode != CConsole.KEY_ESC) && (KeyCode != CConsole.KEY_ENTER));
            if (IsEscPressed())
            {
                Result = 0;
            }
            System.Console.CursorVisible = false;
            Color = SavedColor;
            Clear();
            System.Console.CursorVisible = SavedCursor;
            return(Result);
        }