Beispiel #1
0
        /// <summary>Draws the specified text.</summary>
        /// <param name="left">The column.</param>
        /// <param name="top">The line.</param>
        /// <param name="text">The text.</param>
        /// <param name="foreground">The foreground.</param>
        /// <param name="background">The background.</param>
        /// <param name="clearLine">if set to <c>true</c> line is cleared before drawing.</param>
        public void WriteLine(int left, int top, string text, ConsoleColor foreground, ConsoleColor background, bool clearLine)
        {
            Win32Console.CHAR_INFO[] bufferToWrite;

            if (clearLine)
            {
                Win32Console.CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
                Win32Console.GetConsoleScreenBufferInfo(outputHandle, out bufferInfo);
                bufferToWrite = CreateBuffer(bufferInfo.dwSize.X, foreground, background);
                InsertInBuffer(bufferToWrite, (short)left, text, foreground, background);
                left = 0;
            }
            else
            {
                bufferToWrite = CreateBuffer(text, foreground, background);
            }

            var rect = new Win32Console.SMALL_RECT {
                Left = (short)left, Top = (short)top, Right = (short)(left + bufferToWrite.Length), Bottom = (short)(top + 1)
            };

            Win32Console.WriteConsoleOutput(
                outputHandle,
                bufferToWrite,
                new Win32Console.COORD {
                X = (short)bufferToWrite.Length, Y = 1
            },
                new Win32Console.COORD {
                X = 0, Y = 0
            },
                ref rect);
        }
Beispiel #2
0
        public void WriteLine(int left, int top, char character, ConsoleColor foreground, ConsoleColor background)
        {
            if (readonlySections[left, top])
            {
                return;
            }

            short attribute     = ConsoleColorToColorAttribute(foreground, background);
            var   bufferToWrite = new[] { new Win32Console.CHAR_INFO {
                                              attributes = attribute, charData = character
                                          } };

            var rect = new Win32Console.SMALL_RECT {
                Left = (short)left, Top = (short)top, Right = (short)(left + bufferToWrite.Length), Bottom = (short)(top + 1)
            };

            Win32Console.WriteConsoleOutput(
                outputHandle,
                bufferToWrite,
                new Win32Console.COORD {
                X = (short)bufferToWrite.Length, Y = 1
            },
                new Win32Console.COORD {
                X = 0, Y = 0
            },
                ref rect);
        }