C# 将readline语句放在中间

C# 将readline语句放在中间,c#,console,console-application,center,readline,C#,Console,Console Application,Center,Readline,我即将开始一个项目,下面是我目前在欢迎屏幕上看到的内容 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" }; strin

我即将开始一个项目,下面是我目前在欢迎屏幕上看到的内容

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]);
}
string[]欢迎=新字符串[4]
{ 
“欢迎”,
“通过输入数字并单击“输入”,选择下面的选项。”,
“1.查看C:\\Windows\\File目录”,
“2.查看您自己的自定义目录”
};
字符串用户选择;
对于(int x=0;x<4;x++)
{
控制台写入线(
“{0,”+((Console.WindowWidth/2)+欢迎[x].Length/2)+“}”,欢迎[x]);
}

我该如何将阅读线居中?因此,当用户选择时,他们的选择也将居中?

您可以使用
CursorLeft
CursorTop
属性移动光标。
因此,在您的情况下,您可以这样做:

Console.CursorLeft = Console.WindowWidth / 2;
// maybe -1 to center the typed number correctly

您可以使用
CursorLeft
CursorTop
属性移动光标。
因此,在您的情况下,您可以这样做:

Console.CursorLeft = Console.WindowWidth / 2;
// maybe -1 to center the typed number correctly

我认为您应该像以前一样使用.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();
string[]welcome=new string[4]{“welcome”,“通过输入数字并单击Enter来选择下面的选项”,“1.查看C:\\Windows\\File目录”,“2.查看您自己的自定义目录”};
字符串用户选择;
对于(int x=0;x<4;x++)
{
WriteLine(“{0,”+((Console.WindowWidth/2)+欢迎[x].Length/2)+“}”,欢迎[x]);
}
var cprompt=“选择:”;
Write(string.Format(“{0,”+((Console.WindowWidth/2)+(cprompt.Length/2))+“}”,cprompt));
Console.ReadLine();

我认为您应该像以前一样使用.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();
string[]welcome=new string[4]{“welcome”,“通过输入数字并单击Enter来选择下面的选项”,“1.查看C:\\Windows\\File目录”,“2.查看您自己的自定义目录”};
字符串用户选择;
对于(int x=0;x<4;x++)
{
WriteLine(“{0,”+((Console.WindowWidth/2)+欢迎[x].Length/2)+“}”,欢迎[x]);
}
var cprompt=“选择:”;
Write(string.Format(“{0,”+((Console.WindowWidth/2)+(cprompt.Length/2))+“}”,cprompt));
Console.ReadLine();
“然后单击Enter”-->我很好奇您将如何处理:)“然后单击Enter”-->我很好奇您将如何处理:)