System.WindowsConsoleDriver.MoveBufferArea C# (CSharp) Method

MoveBufferArea() public method

public MoveBufferArea ( int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, Char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor ) : void
sourceLeft int
sourceTop int
sourceWidth int
sourceHeight int
targetLeft int
targetTop int
sourceChar Char
sourceForeColor ConsoleColor
sourceBackColor ConsoleColor
return void
		public void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight,
					int targetLeft, int targetTop, Char sourceChar,
					ConsoleColor sourceForeColor, ConsoleColor sourceBackColor)
		{
			if (sourceForeColor < 0)
				throw new ArgumentException ("Cannot be less than 0.", "sourceForeColor");

			if (sourceBackColor < 0)
				throw new ArgumentException ("Cannot be less than 0.", "sourceBackColor");

			if (sourceWidth == 0 || sourceHeight == 0)
				return;

			ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo ();
			GetConsoleScreenBufferInfo (outputHandle, out info);
			CharInfo [] buffer = new CharInfo [sourceWidth * sourceHeight];
			Coord bsize = new Coord (sourceWidth, sourceHeight);
			Coord bpos = new Coord (0, 0);
			SmallRect region = new SmallRect (sourceLeft, sourceTop, sourceLeft + sourceWidth - 1, sourceTop + sourceHeight - 1);
			fixed (void *ptr = &buffer [0]) {
				if (!ReadConsoleOutput (outputHandle, ptr, bsize, bpos, ref region))
					throw new ArgumentException (String.Empty, "Cannot read from the specified coordinates.");
			}

			int written;
			short attr  = GetAttrForeground (0, sourceForeColor);
			attr  = GetAttrBackground (attr, sourceBackColor);
			bpos = new Coord (sourceLeft, sourceTop);
			for (int i = 0; i < sourceHeight; i++, bpos.Y++) {
				FillConsoleOutputCharacter (outputHandle, sourceChar, sourceWidth, bpos, out written);
				FillConsoleOutputAttribute (outputHandle, attr, sourceWidth, bpos, out written);
			}

			bpos = new Coord (0, 0);
			region = new SmallRect (targetLeft, targetTop, targetLeft + sourceWidth - 1, targetTop + sourceHeight - 1);
			if (!WriteConsoleOutput (outputHandle, buffer, bsize, bpos, ref region))
				throw new ArgumentException (String.Empty, "Cannot write to the specified coordinates.");
		}