7

I'm creating a prototype for a piece of functionality that I will be implementing in an application, specifically I am displaying data from a collection to the console window but unfortunately some of the lines span wider than the default width of the console window.

alt text

I've done a bit of digging and found that the only way to increase the width of the window is to dig into the Kernel32.dll and do it manually.

As elegant as pInvoke is, does a "shorter" way exist to increase the width e.g. (Console.Width = 300) or is using the Kernel32.dll the only way.

Thanks!

1
  • What's in elegant about PINVOKE? Commented Nov 8, 2010 at 10:36

1 Answer 1

6

No programming is required. Create a shortcut to your program on the desktop. Right-click it, Properties, Layout tab. Adjust the Width property of the screen buffer and window size.

But you can do it programmatically too, those Windows API functions you found are wrapped by the Console class as well. You first have to make sure that the console buffer is large enough, then you can set the window size to a size that's less or equal to the buffer size. For example:

 static void Main(string[] args) { if (!Console.IsOutputRedirected) { Console.BufferWidth = 100; Console.SetWindowSize(Console.BufferWidth, 25); } Console.ReadLine(); } 
Sign up to request clarification or add additional context in comments.

2 Comments

But this is not maximising the windows, it's just changing the size of the window. Am I missing something? Is it different for Windows 7 and 10?
Read the question, the OP only wants his console window bigger so the text fits. I'll edit the title.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.