gpt4 book ai didi

c# - 将 readline 语句居中

转载 作者:太空宇宙 更新时间:2023-11-03 20:20:33 24 4
gpt4 key购买 nike

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

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]);
}

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

最佳答案

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

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

关于c# - 将 readline 语句居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13824769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com