1

我即将开始一个项目,这是我目前的欢迎屏幕。

string[] welcome = new string[4] 
{ 
    "Welcome", 
    "Choose A Option Bellow By Inputing The Number And Clicking Enter.", 
    "1. View C:\\Windows\\ File directory", 
    "2. View Your Own Custom Directory" 
};

string userChoice;
for (int x = 0; x < 4; x++)
{
    Console.WriteLine(
        "{0," + ((Console.WindowWidth / 2) + welcome[x].Length / 2) + "}", welcome[x]);
}

我如何使我的阅读线居中?这样当用户选择时,他们的选择也会居中?

4

2 回答 2

5

CursorLeft您可以使用和CursorTop属性移动光标。
所以,在你的情况下,你会做这样的事情:

Console.CursorLeft = Console.WindowWidth / 2;
// maybe -1 to center the typed number correctly
于 2012-12-11T16:56:05.333 回答
0

我相信您应该像以前一样使用 .Write() 和格式。然后,在后面添加一个 Readline/ReadKey:

            string[] welcome = new string[4] { "Welcome", "Choose A Option Bellow By Inputing The Number And Clicking Enter.", "1. View C:\\Windows\\ File directory", "2. View Your Own Custom Directory" };
        String userChoice;
        for (int x = 0; x < 4; x++)
        {
            Console.WriteLine("{0," + ((Console.WindowWidth / 2) + welcome[x].Length / 2) + "}", welcome[x]);
        }
        var cprompt = "Choice:";
        Console.Write(string.Format("{0," + ((Console.WindowWidth / 2) + (cprompt.Length/2)) + "}", cprompt ));
        Console.ReadLine();
于 2012-12-11T17:06:13.400 回答