示例#1
0
        static void Main(string[] args)
        {
            Direction direct1 = Direction.NoDiction;

            Console.WriteLine("direct1 : {0} ({1})", direct1, (int)direct1);

            direct1++;

            Console.WriteLine("direct1 : {0} ({1})", direct1, (int)direct1);

            direct1++;

            Console.WriteLine("direct1 : {0} ({1})", direct1, (int)direct1);

            #region Ввод значений перечисления

            Console.Write("[");
            // получение всех значений перечисления
            string[] namesOfDirection = Enum.GetNames(typeof(Direction));
            for (int i = 0; i < namesOfDirection.Length - 1; i++)
            {
                Console.Write("{0}, ", namesOfDirection[i]);
            }
            Console.WriteLine("{0}]", namesOfDirection[namesOfDirection.Length - 1]);

            Console.Write("Choice direction: ? ");

            string sDirect = Console.ReadLine();

            Direction userDirection;

            //               (string) ---> enum
            //if (!(Enum.TryParse(sDirect, out userDirection)    // преобразование sDirect ---> userDirection
            //    && (userDirection > Direction.NoDiction)       //   проверка на допустимые
            //    && (userDirection <= Direction.Down)))         //         значения
            if (!Enum.TryParse(sDirect, out userDirection) || // преобразование sDirect ---> userDirection
                (userDirection <= Direction.NoDiction) ||     //   проверка на допустимые
                (userDirection > Direction.Down))             //         значения
            {
                Console.WriteLine("Wrong direction...");

                Console.ReadKey();
                return;    // завершение работы программы
            }

            switch (userDirection)
            {
            case Direction.Left:
                Console.WriteLine("Лево");
                break;

            case Direction.Right:
                Console.WriteLine("Право");
                break;

            case Direction.Up:
                Console.WriteLine("Верх");
                break;

            case Direction.Down:
                Console.WriteLine("Низ");
                break;

            case Direction.NoDiction:
            default:
                Console.WriteLine("Wrong direction... ({0})", (int)userDirection);
                break;
            }

            BorderItem lt = BorderItem.LeftTopDoubleCorner;

            Console.WriteLine("Border: {0} {1} ({2:X})", lt, (char)lt, (ushort)lt);

            lt = BorderItem.LeftDownDoubleCorner;

            Console.WriteLine("Border: {0} {1} ({2:X})", lt, (char)lt, (ushort)lt);

            lt++;

            Console.WriteLine("Border: {0} {1} ({2:X})", lt, (char)lt, (ushort)lt);

            #endregion

            #region Битовые перечисления

            // ConsoleKey - стандартное перечисление для всех клавиш клавиатуры

            Console.ForegroundColor = ConsoleColor.Cyan;

            FDirection direct2 = FDirection.Left | FDirection.Up;

            Console.WriteLine("direct2 : {0} ({1})", direct2, (int)direct2);

            if ((direct2 & FDirection.Up) > 0)
            {
                Console.WriteLine("Flag \"Up\" is set");
            }
            else
            {
                Console.WriteLine("Flag \"Up\" is unset");
            }

            if ((direct2 & FDirection.Down) > 0)
            {
                Console.WriteLine("Flag \"Down\" is set");
            }
            else
            {
                Console.WriteLine("Flag \"Down\" is unset");
            }

            if (direct2.HasFlag(FDirection.Left))
            {
                Console.WriteLine("Flag \"Left\" is set");
            }
            else
            {
                Console.WriteLine("Flag \"Left\" is unset");
            }

            #endregion

            Console.ReadKey();
        }
示例#2
0
        private void ApplySnapOnMove(FDirection direction = FDirection.Both)
        {

            int msl;
            if (HaveDirection(direction, FDirection.Horizontal))
            {
                msl = Left % Snap;
                if (msl != 0)
                    Left += (Snap - msl);
            }

            if (HaveDirection(direction, FDirection.Vertical))
            {
                msl = Top % Snap;
                if (msl != 0)
                    Top += (Snap - msl);
            }
            Refresh();
        }
示例#3
0
        private void ApplySnapResize(FDirection direction = FDirection.Both)
        {
            int msl;
            if (HaveDirection(direction, FDirection.Horizontal))
            {
                msl = Width % Snap;
                if (msl != 0)
                    Width += (Snap - msl);
            }

            if (HaveDirection(direction, FDirection.Vertical))
            {
                msl = Height % Snap;
                if (msl != 0)
                    Height += (Snap - msl);
            }
            Refresh();
        }
示例#4
0
 private bool HaveDirection(FDirection direction, FDirection have)
 {
     return direction == have || (direction & have) == have;
 }