6

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.

bobthemac
  • 1,172
  • 6
  • 26
  • 59
  • I have used the Console.SetWindowPosition an I can get it to do what I want for the bottom few then it just stops. – bobthemac Jan 04 '12 at 16:38
  • I have Solved the issue I used Console.SetWindowPosition(0 , currentItem); and it worked perfectly but I wouldn't have found it if it weren't for you guys telling my to set the cursor position thanks for all the help. – bobthemac Jan 04 '12 at 17:05

5 Answers5

7
Console.SetCursorPosition(XCoordinate,YCoordinate);

Should do the trick.

Icarus
  • 63,293
  • 14
  • 100
  • 115
  • +1. Oh, I like this idea. While it also doesn't actually answer the question, it does provide another work around. I suspect the OP won't like it either though :( – McKay Jan 04 '12 at 16:07
  • @bobthemac: The bottom line is that this is the method that you need to use if you want to move the cursor to a specific scroll position. If it messes up your menu write code, you probably need to re-write that routine. There isn't much to add, sorry. – Icarus Jan 04 '12 at 16:12
  • I don't want to move the cursor I want to scroll to a specific point should I post my menu code. – bobthemac Jan 04 '12 at 16:16
  • I Have tried this an edited my code to make it fit but it still jumps to the bottom when I change my selection. – bobthemac Jan 04 '12 at 16:54
3

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

Console.SetWindowPosition(0 , currentItem);
bobthemac
  • 1,172
  • 6
  • 26
  • 59
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.

McKay
  • 12,334
  • 7
  • 53
  • 76
  • I don't think I was clear with my question I run a clear before I refresh the menu I want to change the physical scroll position of the console to show the current selected option. – bobthemac Jan 04 '12 at 16:03
  • 1
    @bobthemac Yes, I think you were clear with that, but I'm not aware of any console options that do that. Maybe it's time you upgraded to a windows forms application, where you have more direct access to the scroll bars? – McKay Jan 04 '12 at 16:05
  • I would use windows forms but I have been told that it has to be a console application – bobthemac Jan 04 '12 at 16:10
1

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

Community
  • 1
  • 1
Dan Rigby
  • 17,133
  • 6
  • 43
  • 60
1

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.

Tigran
  • 61,654
  • 8
  • 86
  • 123