title: How Can I change the background color of a text on a Console Application C#
body: <p>I am writing a small console application in c# and I want to use the arrow keys to navigate through my menu. To make the selected option visible to the user I want to highlight it with a white background and black text but only the word and not the whole line.</p>
  
  <p>I tried to position the cursor at the beginning of the word so only the word would be highlighted but it did not work. Could someone put me on the right direction, please?</p>
  
  <pre><code>for (int i = 0; i &lt; filesArray.Length; i++)
          {
              Console.WriteLine();
  
              if (i == 0)
              {
                  Console.BackgroundColor = ConsoleColor.White;
                  Console.ForegroundColor = ConsoleColor.Black;
                  Program.WriteAtTheMiddleOfTheScreen(filesArray[0]);
                  Console.ResetColor();
              }
              else
              {
  
                  Program.WriteAtTheMiddleOfTheScreen(filesArray[i]);
              }
          }
  
          Console.WriteLine();
          Program.WriteAtTheMiddleOfTheScreen("Exit Program");
  
          Console.SetCursorPosition((Console.WindowWidth/2)-filesArray[0].Length+2, 2);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/2RgQL.png" rel="nofollow noreferrer">That is what I want to achieve</a></p>
  
  <p><a href="https://i.stack.imgur.com/sqUts.png" rel="nofollow noreferrer">That is how it looks like</a></p>
  
  <pre><code>public static void WriteAtTheMiddleOfTheScreen(string message)
      {
          message = String.Format("{0," + ((Console.WindowWidth / 2) +    (message.Length / 2)) + "}", message);
          Console.WriteLine(message);
      }
  </code></pre>