rshea0
rshea0

Reputation: 12249

Draw a block of text to a certain position in the console?

I know how to set the cursor position of the console, but upon creating a new line, the cursor moves back to the left side of the console.

How do I set the cursor position and write multiple lines while retaining the cursor's x coordinate?

Note: It is note an option for me to set the cursor position for every line, as my block of text changes size often.

Upvotes: 2

Views: 668

Answers (2)

Thomas Levesque
Thomas Levesque

Reputation: 292465

void WriteLineKeepingIndent(string format, params object[] args)
{
    int x = Console.CursorLeft;
    Console.WriteLine(format, args);
    Console.CursorLeft = x;
}

Upvotes: 5

igofed
igofed

Reputation: 1442

You should use one of

  1. Before each Console.WriteLine() set Console.CursorLeft
  2. Use PadLeft method on strings

Upvotes: 0

Related Questions