我想在C#一个简单的菜单,如: 这样的事情应该打印出控制台:使在C#中简单的控制台菜单
FirstOption
SecondOption
Exit
到目前为止,这里是我的代码(有与命名问题和封装,而这一切只是快速原型,花了约30分钟):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Menu StartGame = new Menu("Start Game");
Menu EndGame = new Menu("End Game");
Console.WriteLine(StartGame);
Console.WriteLine(End Game);
EndGame.isChecked = false;
}
}
class Menu
{
private string Content;
public bool isChecked = true;
public Menu(string Content)
{
this.Content = Content;
}
public void CheckCondition()
{
if (isChecked)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
}
else
{
Console.ResetColor();
}
}
public override string ToString()
{
this.CheckCondition();
return this.Content;
}
}
}
的想法是,当点击一个按钮,菜单项被高亮显示。当有人来到最后一个菜单项时,他不能再次按DownArrow
,对于第一项和UpArrow
也是如此。
我完全被卡住与此有关。
http://img688.imageshack.us/img688/9655/menu2xa.png这样的事情,但与其他颜色 – 2013-03-17 16:33:41
写作UI在诅咒真的很难,P – leppie 2013-03-17 16:41:30
有你为什么不使用任何特殊的理由WinForms? – Shrikey 2013-03-17 16:56:57