【问题标题】:Can you make a feature that allows users to choose color C# (Console) [closed]你能做一个允许用户选择颜色的功能C#(控制台)[关闭]
【发布时间】:2016-12-25 00:54:00
【问题描述】:

有什么想法吗?我有办法,但只会从下往上改变,菜单在顶部。

【问题讨论】:

  • 不是一个明确的问题,没有你到目前为止所做的代码示例,没有以前研究的例子,有点像家庭作业。
  • 是的,你可以......现在去阅读

标签: c# colors console


【解决方案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);
    }
}

【讨论】:

  • 必须同时设置 BackgroundColor 和 ForegroundColor。并清除控制台
猜你喜欢
  • 2011-08-22
  • 2012-07-17
  • 1970-01-01
  • 2021-11-02
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
  • 2018-07-24
  • 1970-01-01
相关资源
最近更新 更多