Console.SetWindowPosition() Method in C#
Console.SetWindowPosition(Int32, Int32) Method in C# is used to set the position of the console window relative to the screen buffer.
Syntax: public static void SetWindowposition(int left, int top);
Parameters:
left: It is the column position of the upper left corner of the console window.
top: It is the row position of the upper left corner of the console window.
Exceptions:
- ArgumentOutOfRangeException: When left or top is less than 0 or left + WindowWidth > BufferWidth or top + Windowheight > BufferHeight.
- SecurityException: If the user doesn’t have the permission to perform this action.
Example:
using System;
using System.Text;
using System.IO;
class GFG {
public static void Main( string [] args)
{
Console.SetWindowSize(20, 20);
Console.SetBufferSize(80, 80);
Console.SetWindowPosition(0, 0);
Console.WriteLine( "Hello GFG!" );
Console.Write( "Press any key to continue . . . " );
Console.ReadKey( true );
}
}
|
Output:
When Console.WindowPosition() method is not used:
Reference:
Last Updated :
14 Mar, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...