Search code examples
c#.netwinapipinvokedllimport

Strange SetConsoleScreenBufferInfoEx behavior


If i create a C# console application which sets the console Buffer/Window Width and Height (using Console.*-Methods) to 80x25 (or any other specific size) the console-window has no scrollbars.

When i use GetConsoleScreenBufferInfoEx to read the consolebuffer-settings it reports a window.Right and window.Bottom of 79x24. If i write the read CONSOLE_SCREEN_BUFFER_INFO_EX back the window will get scrollbars.

Question: Are there any C#/.NET-framework methods interfering or is this standard behavior?

I've seen examplecode for C on the internet which is always doing window.Right++ and window.Bottom++.


Solution

  • For the first question, I think you're getting scroll bars because your window is actually getting smaller. It's a bug.

    See 35901572 and note, for reference that the examples on PInvoke always fix the size.

    Try adding a couple lines after you call GetConsoleScreenBufferInfoEx:

    GetConsoleScreenBufferInfoEx(handle, ref currentScreen);
    ++currentScreen.srWindowBottom;
    ++currentScreen.srWindowRight;