예제 #1
0
        /// <summary>
        /// Writes characters from a character array to the screen buffer at the given cursor position.
        /// </summary>
        /// <param name="text">An array containing the characters to be written.</param>
        /// <param name="nChars">The number of characters to be written.</param>
        /// <param name="x">Column position in which to write the first character.</param>
        /// <param name="y">Row position in which to write the first character.</param>
        /// <returns>Returns the number of characters written.</returns>
        public int WriteXY(char[] text, int nChars, int x, int y)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }
            if (nChars > text.Length)
            {
                throw new ArgumentException("nChars cannot be larger than the array length.");
            }
            int   charsWritten = 0;
            Coord writePos     = new Coord((short)x, (short)y);

            if (!WinCon.WriteConsoleOutputCharacter(_handle, text, nChars, writePos, ref charsWritten))
            {
                throw new System.IO.IOException("Write error", Marshal.GetLastWin32Error());
            }
            return(charsWritten);
        }