I am trying to draw a box in a console but I cant figure out to do it without entering a new line.
I make something like this:
-----
| |
_____
But the input line comes directly underneath it and removing the upper row of the box.
I tried with Console.setCursorPosition but the last line is already filled thus already a new line created.
How can I prevent the new line from being created?
Thanks in advance
Edit
It is possible to use the console window as a canvas?
Lets assume a window with the following size
Height : 50
Width : 100
I can place any character on any of the tiles within the above given console size.
Would this be possible if so how?
It would be helpful if you posted code you wrote to create this box from ASCII chars.
If you use
Console.WriteLine(), just useConsole.Write()method for the last line instead. So, for the box in your question the code can look like:Let me know if this helps.
I made a test in a sample application and the extra line seems not to be created.
Update
If you want to use the box a border to the Console window, I suppose it would be the easiest solution (if not the only one) not to add the last – character in the bottom line of the box you are drawing.
Update II
You can try to use a simple trick and dynamically change height of the console window before drawing the last line. This will prevent the window from being scrolled.
Try code like this:
This should allow you to get the whole border visible in the window.
Update III
The suggested solution
Use the code above, but with
Console.BufferWidthinstead ofConsole.WindowHeight. It seems to work correctly and does not require to modify window’s dimensions.