Console and scrolling

  • Thread starter Thread starter PHead
  • Start date Start date
P

PHead

Is there any way to stop the console from scrolling? What I mean isnt
to not scroll at all, its that I want to get rid of the buffer. When a
new line is created, I want row 0 to go away permanently, not just be
scrolled out of view. No scroll bars, etc. I know the C# console is
weak, but even via Win32 API?
 
PHead said:
Is there any way to stop the console from scrolling? What I mean isnt
to not scroll at all, its that I want to get rid of the buffer. When
a new line is created, I want row 0 to go away permanently, not just
be scrolled out of view. No scroll bars, etc. I know the C# console is
weak, but even via Win32 API?

That's a good question. Generally speaking, a console application has no
influence over how the command shell application behaves, which is what
you're attempting to do. One way to achieve what you want is to create a
two-dimensional array of characters representing the screen:

char screen = new char[Console.WindowHeight, Console.WindowWidth];

Now, do all your printing into a buffer using MemoryStream. When you're
ready, write the stored characters on the virtual screen yourself,
performing your own scrolling. Finally, use Console.SetCursorPosition()
along with normal writing functions to write out the contents of the screen
buffer onto the real console. If you do this each time you need to draw
something on the screen, it should never have a chance to scroll.
Unfortunately, this is probably more work than it's worth. I hope this
helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top