你能做出一个让用户选择颜色C#(控制台)的功能吗?

时间:2016-08-18 07:31:10

标签: c# colors console

有什么想法吗?我有办法,但只会从向下变化,菜单位于顶部。

1 个答案:

答案 0 :(得分:1)

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("input BackgroundColor:");
        string bcolor = Console.ReadLine();
        Console.WriteLine("input ForegroundColor:");
        string fcolor = Console.ReadLine();
        ChangeColorConsole(bcolor, fcolor);
        Console.Read();
    }

    static void ChangeColorConsole(string bvalue, string fvalue)
    {
        Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), bvalue);
        Console.Clear();
        Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), fvalue);
    }
}