'C# is there a way to set the scroll position of a console application

Hi I have been Googling this question for quite a while and cant find any results on how I would go about doing this. I currently have a selection menu that the user can select a list of options from and this starts at the top but the window displays the last options each time I refresh the list. All I want to do is be able to display the line with the selected option on in the window.

any ideas will be appreciated.



Solution 1:[1]

Console.SetCursorPosition(XCoordinate,YCoordinate);

Should do the trick.

Solution 2:[2]

I think what you might want is

System.Console.Clear()

It clears the entire console screen, and removes all the contents. That's about all you've got access to though without serious work.

You can set the cursor position and window position which are useful for some things, but it won't really scroll back in most cases.

Solution 3:[3]

This might be helpful to you:

Console.SetCursorPosition(int left, int top)

From MSDN:

Use the SetCursorPosition method to specify where the next write operation in the console window is to begin. If the specified cursor position is outside the area that is currently visible in the console window, the window origin changes automatically to make the cursor visible.

This StackOverflow answer gives an example on how to use it: https://stackoverflow.com/a/3407570/53777

Solution 4:[4]

This should work for you

Console.SetCursorPosition(columnID, rowID);

Try to do something like this:

Console.WriteLine("Hello");            
Console.ReadLine();
Console.SetCursorPosition(10, 40);
Console.WriteLine(" world");
Console.ReadLine();

to see, if this is what you're searching for.

Hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Icarus
Solution 2
Solution 3 Community
Solution 4 Tigran