1

I'm trying to set the background and foreground colors of my console application. But no matter what I try, the colors do not differ from the default black & white. This is the beginning of my Main method. I've tried with and without Console.Clear()

Console.ForegroundColor = ConsoleColor.Green;
Console.Clear();

I've checked MSDN and searched SO already, and the above example seems to work for everybody else. Any advice?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Link
  • 11
  • 1
  • Have you print something yet in the console to verifyif it is working? Because the code you posted is not showing it. – Sandip Ghosh Dec 16 '17 at 13:58
  • This is the only code? Just two of these lines? – Berkay Yaylacı Dec 16 '17 at 13:58
  • No, there is more - the next line just writes to the console: Console.WriteLine("Welcome to the Create-A-Menu app!"); But I've also tried setting the background color with no success – Link Dec 16 '17 at 14:01
  • That's the way to do it. Maybe you're using a different commandline shell? Try explicitly running cmd.exe, navigating to you app and running it via that commandline. – Ridiculous Dec 16 '17 at 14:09
  • 1
    Try running visual studio as administrator. – Berkay Yaylacı Dec 16 '17 at 14:11
  • 1
    Interesting - opening the project in visual studio as an administrator worked. Thanks @Berkay – Link Dec 16 '17 at 14:27
  • Possible duplicate of [Is it possible to write to the console in colour in .NET?](https://stackoverflow.com/questions/2743260/is-it-possible-to-write-to-the-console-in-colour-in-net) – codebender Dec 16 '17 at 14:48

1 Answers1

1

Try this:

class Program
{
    static void Main(string[] args)
    {
        Console.BackgroundColor = ConsoleColor.Red;
        Console.Clear();
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Red background and white letters");
        Console.ReadKey();
    }
}
Slaven Tojić
  • 2,945
  • 2
  • 14
  • 33