C#多个SetCursorPosition但第一个被跳过

时间:2019-09-13 05:29:59

标签: c#

您好,在我的c#控制台应用程序中,我有一个方法可以多次调用Console.SetCursorPosition来输入多个用户输入,但是当我运行该程序时,第一个输入将被跳过。我希望我的输出看起来像:

名字:(此处为光标)

姓:

地址:

电话:

电子邮件:

当前光标出现在姓氏旁边。 对于可能发生这种情况的任何想法将不胜感激。

String firstNameLbl = "First Name:";
String lastNameLbl = "Last Name:";
String addressLbl = "Address:";
String phoneLbl = "Phone Number:";
String emailLbl = "Email Address:";

Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + heading1.Length / 2) + "}", heading1));
Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + heading2.Length / 2) + "}", heading2));

Console.Write("\n" + String.Format("{0," + ((Console.WindowWidth / 4) + firstNameLbl.Length - 3) + "}", firstNameLbl));
Console.Write("\n" + String.Format("{0," + ((Console.WindowWidth / 4) + lastNameLbl.Length - 3) + "}", lastNameLbl));
Console.Write("\n" + String.Format("{0," + ((Console.WindowWidth / 4) + addressLbl.Length - 3) + "}", addressLbl));
Console.Write("\n" + String.Format("{0," + ((Console.WindowWidth / 4) + phoneLbl.Length - 3) + "}", phoneLbl));
Console.Write("\n" + String.Format("{0," + ((Console.WindowWidth / 4) + emailLbl.Length - 3) + "}", emailLbl));

Console.SetCursorPosition((Console.WindowWidth / 4) + firstNameLbl.Length - 3, 3);
firstName = Console.ReadLine();


Console.SetCursorPosition((Console.WindowWidth / 4) + lastNameLbl.Length - 3, 4);
lastName = Console.ReadLine();

Console.SetCursorPosition((Console.WindowWidth / 4) + addressLbl.Length - 3, 5);
address = Console.ReadLine();

Console.SetCursorPosition((Console.WindowWidth / 4) + phoneLbl.Length - 3, 6);
phoneNumber = Convert.ToInt32(Console.ReadLine());

Console.SetCursorPosition((Console.WindowWidth / 4) + emailLbl.Length - 3, 7);
email = Console.ReadLine();

0 个答案:

没有答案