是否可以在C#Windows控制台应用程序中的固定位置处显示变量的值,以使其可见,而屏幕内容则否则会将每个旧值向上推而看不见,从而不再打印该值并再次换行?
我知道Curses,但是想使用任何标准(如果存在),并学习如何做。
感谢您的时间和帮助。
该Console.SetCursorPosition是在控制台窗口的特定点插入位置所需要的架构方法。当然,设置一个点然后会将随后的所有写操作从新点开始转移到控制台,因此,如果要在精确位置写一些内容然后从上一个点重新开始,则还需要处理上一个写操作的位置。
这只是一个入门的例子
static void Main()
{
for (int x = 0; x < 100; x++)
{
if (x % 10 == 0)
Console.SetCursorPosition(0, 0);
else
Console.SetCursorPosition(0, x % 10);
Console.WriteLine(x);
WriteStatusText("Printing line " + x);
// Remove this comment to see it slowly
// Console.ReadLine();
}
Console.ReadLine();
}
static void WriteStatusText(string msg)
{
Console.SetCursorPosition(0, 10);
Console.WriteLine(msg);
}
请记住,将位置设置为为控制台定义的缓冲区(Console.BufferWidth和Console.BufferHeight)之外会触发异常
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句