我想将光标在控制台中的位置设置为最后一个可见行。我该怎么做?
干杯,
皮特
最佳答案
如果您指的是窗口的最后一行,您可以混合使用 Console.CursorTop
、Console.WindowHeight
和 Console.WindowTop
。示例代码:
using System;
class Test
{
static void Main()
{
Console.Write("Hello");
WriteOnBottomLine("Bottom!");
Console.WriteLine(" there");
}
static void WriteOnBottomLine(string text)
{
int x = Console.CursorLeft;
int y = Console.CursorTop;
Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1;
Console.Write(text);
// Restore previous position
Console.SetCursorPosition(x, y);
}
}
请注意,这必须考虑 Console.WindowTop
才能找出您在缓冲区中的位置...
关于C# 控制台 - 将光标位置设置为最后一个可见行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3407548/