Rewriting characters in command window

家住魔仙堡 提交于 2019-12-20 02:49:39

问题


I want to output some characters in C# console application and then rewrite them, thus changing characters in position already occupied in command window. So for for example I could show progress in percentages 10%, 20%, 30% (but in the same place). How can I do that?


回答1:


Have a look at Writing string at the same position using Console.Write in C# 2.0

  • Console.SetCursorPosition Method
  • Console.CursorLeft Property
  • Console.CursorTop Property



回答2:


If you print a '\r' character, the cursor will return back to the current line, e.g.

Console.Write("10%\r");
// then..
Console.Write("20%\r");


来源:https://stackoverflow.com/questions/2370695/rewriting-characters-in-command-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!