我想在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