LucasCalamar
LucasCalamar

Reputation: 11

Why am I getting this error when I try to put a custom color?

When I try to make a custom color I get an error

Code:

Color c = Color.FromArgb (127, 255, 212);

When I use

Console.ForegroundColor = ConsoleColor.c; 

I get an error

"c" is not a valid color

Upvotes: 0

Views: 90

Answers (2)

Jazimov
Jazimov

Reputation: 13292

The console can accept colors only from the ConsoleColor enum. You cannot assign a custom color, unfortunately.

You must use code like this:

Console.ForegroundColor = ConsoleColor.DarkBlue;

For a comprehensive list of colors, look here: https://learn.microsoft.com/en-us/dotnet/api/system.consolecolor

Upvotes: 2

Nekuskus
Nekuskus

Reputation: 145

The ConsoleColor enum and Drawing.Color class are sadly two different things. The second is only for WinForms use. The Console has only the preset colors. More information about the colors console uses can be found here. About the ConsoleColor enum, take a look at this documentation. And for Drawing.Color take a look at this documentation.

Upvotes: 1

Related Questions