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:
// C# Program to illustrate the use of // Console.WindowPosition() method using System; using System.Text; using System.IO; class GFG { // Main Method public static void Main( string [] args) { Console.SetWindowSize(20, 20); // setting buffer size Console.SetBufferSize(80, 80); // using the method 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:
- https://docs.microsoft.com/en-us/dotnet/api/system.console.setwindowposition?view=netframework-4.7.2
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Uri.GetHashCode() Method
- C# | CopyTo() Method
- C# | Dictionary.Add() Method
- C# | CompareOrdinal() Method
- C# | Clone() Method
- C# | Insert() Method
- Stack.Pop() Method in C#
- C# | Replace() Method
- C# | Remove() Method
- Extension Method in C#
- C# | IndexOfAny() Method
- C# | Math.Log() Method
- jQuery | get() Method
- C# | Uri.IsHexDigit() Method
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.