Beispiel #1
0
        public void DrawRect(XRect rect, ConsoleColor color)
        {
            // 调整矩形
            rect.Adjust(ref rect);

            int x      = rect.GetX();
            int y      = rect.GetY();
            int width  = rect.GetWidth();
            int height = rect.GetHeight();

            // 根据符号设置对应的颜色
            if (m_symbol == XSymbol.DEFAULT)
            {
                Console.BackgroundColor = color;
            }
            else
            {
                Console.BackgroundColor = this.m_backColor;
                Console.ForegroundColor = this.m_backColor == color ? (ConsoleColor)(15 - (Int32)this.m_backColor) : color;
            }

            // 获取符号对应的字符串
            String charSymbol = XSymbolHelper.GetStringFromSymbol(m_symbol);

            // 绘制列
            for (Int32 i = 0; i < width; i++)
            {
                Int32 ix = x + (i << 1);
                if (ix >= Console.WindowWidth)
                {
                    ix = Console.WindowWidth - 1;
                }

                Console.SetCursorPosition(ix, y);
                Console.Write(charSymbol);

                Console.SetCursorPosition(ix, y + height - 1);
                Console.Write(charSymbol);
            }

            // 绘制行
            for (Int32 i = 0; i < height; i++)
            {
                Int32 ix = x + (width << 1) - 2;
                if (ix >= Console.WindowWidth)
                {
                    ix = Console.WindowWidth - 1;
                }

                Console.SetCursorPosition(x, y + i);
                Console.Write(charSymbol);

                Console.SetCursorPosition(ix, y + i);
                Console.Write(charSymbol);
            }

            Console.SetCursorPosition(0, 0);
        }
Beispiel #2
0
        public void FillRect(XRect rect, ConsoleColor color)
        {
            // 调整矩形
            rect.Adjust(ref rect);

            int x      = rect.GetX();
            int y      = rect.GetY();
            int width  = rect.GetWidth();
            int height = rect.GetHeight();

            // 根据符号设置对应的颜色
            if (m_symbol == XSymbol.DEFAULT)
            {
                Console.BackgroundColor = color;
            }
            else
            {
                Console.BackgroundColor = this.m_backColor;
                Console.ForegroundColor = this.m_backColor == color ? (ConsoleColor)(15 - (Int32)this.m_backColor) : color;
            }

            // 获取符号对应的字符串
            String charSymbol = XSymbolHelper.GetStringFromSymbol(m_symbol);

            StringBuilder str_b = new StringBuilder();

            for (Int32 i = 0; i < width; i++)
            {
                str_b.Append(charSymbol);
            }

            for (Int32 i = 0; i < height; i++)
            {
                Console.SetCursorPosition(x, y + i);
                Console.Write(str_b.ToString());
            }

            Console.SetCursorPosition(0, 0);
        }