Console.MoveBufferArea Method in C#

Console.MoveBufferArea Method is used to move the specified screen area to destination area.

Syntax: public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop);

Parameters:
sourceLeft: The leftmost column of the source area.
sourceTop: The topmost row of the source area.
sourceWidth: The number of columns in the source area.
sourceHeight: The number of rows in the source area.
targetLeft: The leftmost column of the destination area.
targetTop: The topmost row of the destination area.



Exceptions:

  • ArgumentOutOfRangeException:
    • One or more of the parameters is less than zero.
    • If sourceLeft or targetLeft is greater than or equal to BufferWidth.
    • If sourceTop or targetTop is greater than or equal to BufferHeight.
    • If sourceTop + sourceHeight is greater than or equal to BufferHeight.
    • If sourceLeft + sourceWidth is greater than or equal to BufferWidth.
  • IOException: If an I/O error occured.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to print GeeksForGeeks
using System;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
        Console.WriteLine("GeeksForGeeks");
    }
}
}

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to change area
// of GeeksForGeeks
using System;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
        Console.WriteLine("GeeksForGeeks");
  
        // using the method
        Console.MoveBufferArea(0, 0, Console.BufferWidth,
                           Console.BufferHeight, 10, 10);
    }
}
}

chevron_right


Output:

Note:

  • See the difference of text positions in output images.
  • If the destination and source parameters specify a position located outside the boundaries of the current screen buffer, only the portion of the source area that fits within the destination area is copied. That is, the source area is clipped to fit the current screen buffer.
  • The MoveBufferArea method copies the source area to the destination area. If the destination area does not intersect the source area, the source area is filled with blanks using the current foreground and background colors. Otherwise, the intersected portion of the source area is not filled.

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.