bobthemac
bobthemac

Reputation: 1172

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.

Upvotes: 6

Views: 11581

Answers (5)

McKay
McKay

Reputation: 12604

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.

Upvotes: 2

bobthemac
bobthemac

Reputation: 1172

This is what I used in the end and it worked as I wanted it to.

Console.SetWindowPosition(0 , currentItem);

Upvotes: 3

Tigran
Tigran

Reputation: 62256

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.

Upvotes: 1

Dan Rigby
Dan Rigby

Reputation: 17883

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

Upvotes: 1

Icarus
Icarus

Reputation: 63966

Console.SetCursorPosition(XCoordinate,YCoordinate);

Should do the trick.

Upvotes: 7

Related Questions