我想在控制台下写一个用光标控制菜单的程序假如一开始输出如下:
1.one
2.two
3.three当光标在3.three的下面时,我按一下向上的光标 3.three 的颜色就变了,
再一下向上的光标2.two的颜色又变了同时间3.three 的颜色回到原来的颜色。
按下光标时就向下改变以。大家帮下忙。谢谢!!
1.one
2.two
3.three当光标在3.three的下面时,我按一下向上的光标 3.three 的颜色就变了,
再一下向上的光标2.two的颜色又变了同时间3.three 的颜色回到原来的颜色。
按下光标时就向下改变以。大家帮下忙。谢谢!!
SetConsoleCursorPosition设置位置
你的问题是不是也和cmd.exe有关啊?
{
public static void Main()
{
string one=" one",two=" two",three=" three";
int x=0, y=0;
ConsoleKeyInfo cki = new ConsoleKeyInfo();
ConsoleKeyInfo cki1 = new ConsoleKeyInfo();
//Console.BackgroundColor = ConsoleColor.Yellow; do
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("+++++++++++++++++++++++++++++++++++++");
Console.WriteLine(one); Console.WriteLine(two); //Console.CursorLeft = Console.CursorTop+2;
Console.WriteLine(three);
;
//Console.BackgroundColor = ConsoleColor.Yellow;
//Console.SetCursorPosition(Console.CursorTop-2, Console.CursorLeft); cki = Console.ReadKey();
while(cki.Key == ConsoleKey.UpArrow)
{
if (Console.CursorTop-1 == 3)
{
Console.SetCursorPosition(0, Console.CursorTop - 1);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(three);
cki1 = Console.ReadKey();
if (cki1.Key == ConsoleKey.Enter)
{
Console.Clear();
Console.WriteLine("you click three");
break;
}
}
if (Console.CursorTop - 2 == 2)
{ Console.SetCursorPosition(0, x = Console.CursorTop - 2);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(two);
cki1 = Console.ReadKey();
if (cki1.Key == ConsoleKey.Enter)
{
Console.Clear();
Console.WriteLine("you click two");
break;
}
}
if (Console.CursorTop - 3 == 1)
{ Console.SetCursorPosition(0, x = Console.CursorTop - 3);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(one);
cki1 = Console.ReadKey();
if (cki1.Key == ConsoleKey.Enter)
{
Console.Clear();
Console.WriteLine("you click one");
break;
} }
}
while (cki.Key == ConsoleKey.DownArrow)
{
}
Console.ReadKey();
} while (true);
}}