I'm trying to create a custom sized border depending on the size of the console window. The problem is when it draws the last line, the cursor jumps down to the next row, which in turn moves the topmost row offscreen.
The buffersize of the console is the same as the consolesize to remove the scrollbars, which makes this possible.
The right one is the complete border, which creates an extra space because it fills the whole row. The left one is just before doing the last row, which does not have any problems (because it has not drawn the last one).
My current code is that of:
static void DrawFrame(string[,] frame)
{
string[] array = new string[frame.GetLength(1)];
string output;
for (int y = 0; y < frame.GetLength(1); y++)
{
output = "";
Console.SetCursorPosition(0, y);
for (int x = 0; x < frame.GetLength(0); x++)
{
output += frame[x, y];
}
array[y] = output;
Console.Write(output);
}
}
The string variable frame has the value of:
╔══════════════════════╗
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
║ ║
╚══════════════════════╝
The intended behaviour is to not create an extra row when doing the last row, which so far i haven't found any solution for.
Any help is appreciated!
PS: Console.CursorVisible = false; is not a solution.
PS2: The code for creating the border is as follows:
static string[,] SetBorder(string[,] frame)
{
for (int y = 0; y < frame.GetLength(1); y++)
{
for (int x = 0; x < frame.GetLength(0); x++)
{
if (y == 0)
{
if (x == 0)
{
frame[x, y] = "╔";
}
else if(x == frame.GetLength(0) - 1)
{
frame[x, y] = "╗";
}
else
{
frame[x, y] = "═";
}
}
else if (y == frame.GetLength(1) - 1)
{
if (x == 0)
{
frame[x, y] = "╚";
}
else if (x == frame.GetLength(0) - 1)
{
frame[x, y] = "╝";
}
else
{
frame[x, y] = "═";
}
}
else
{
if (x == 0 || x == frame.GetLength(0) - 1)
{
frame[x, y] = "║";
}
else
{
frame[x, y] = " ";
}
}
}
}
return frame;
}
The console size is also defined in the beginning as the size of frames dimensions.
Edit1: For those trying to debug my code, I'll link it here.


