简体   繁体   English

如何将控制台应用程序中的光标设置到末尾?

[英]How to set the cursor in a console application to the end?

Lets say i have a console application with these commands: 可以说我有一个带有以下命令的控制台应用程序:

Console.WriteLine("Line1");
Console.WriteLine("Line2");
Console.WriteLine("Line3");
Console.SetCursorPosition(1,0);
Console.Write("\b");

So that the result will look like this: 这样结果将如下所示:

ine1
Line2
Line3

How can i set the cursor Position to the end of everything, so that the cursor Position is after Line3 ? 如何将游标Position设置为所有内容的结尾,以使游标Position位于Line3之后?

I can't set it to something like Cursor.SetCursorPosition(0,3) because the length of all lines is not always the same. 我不能将其设置为Cursor.SetCursorPosition(0,3)因为所有行的长度并不总是相同。

与其尝试根据控制台的文本来检测光标在开始更改之前的位置,不如在更改之前先存储光标的位置(通过读取属性值并将其存储在变量中),这样您就知道要去哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM