Skip to content
Related Articles

Related Articles

Console.SetCursorPosition() Method in C#
  • Last Updated : 14 Mar, 2019

Console.SetCursorPosition(Int32, Int32) Method is used to set the position of cursor. Basically, it specifies where the next write operation will begin in the console window. The window origin changes automatically to make the cursor visible if the specified cursor position is outside the area that is currently visible in the console window.

Syntax: public static void SetCursorposition(int left, int top);

Parameters:
left: It is the column position of the cursor. Columns are numbered from left to right starting at 0.
top: It is the row position of the cursor. Rows are numbered from top to bottom starting at 0.

Exceptions:

  • ArgumentOutOfRangeException: If the left or top is less than 0 or left >= BufferWidth or top >= BufferHeight.
  • SecurityException: If the user doesn’t have the permission to perform this action.

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# Program to illustrate 
// Console.CursorPosition() method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // setting the window size
        Console.SetWindowSize(40, 40);
  
        // setting buffer size of console
        Console.SetBufferSize(80, 80);
  
        // using the method
        Console.SetCursorPosition(20, 20);
        Console.WriteLine("Hello GFG!");
        Console.Write("Press any key to continue . . . ");
  
        Console.ReadKey(true);
    

chevron_right


Output:

When Console.SetCursorPosition() method is not used:

Reference:

My Personal Notes arrow_drop_up
Recommended Articles
Page :