How to change Cursor position in Console?

帅比萌擦擦* 提交于 2020-01-06 09:56:31

问题


I wanted to use Console.ReadLine(); in the previous line and make it display like that:

HeresomeText>(input)

Not like

HeresomeText>
(input)

Is it possible to do?


回答1:


use Write method instead of WriteLine Method:

 Console.Write("HeresomeText> ")

in addition you can use SetCursorPosition:

Console.SetCursorPosition(int left, int right);



回答2:


Absolutely - look at the various members of the System.Console class.

In particular, you want the SetCursorPosition method, but if you're writing a "fancy" console app you should think about the members for using colours etc too.




回答3:


It depends on your previous Console.WriteLine() statement. Change it to Console.Write() which does not have the linebreak.

static void Main(string[] args)
{
    Console.Write("HeresomeText>");
    Console.ReadLine();
}


来源:https://stackoverflow.com/questions/22089645/how-to-change-cursor-position-in-console

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