This question already has an answer here:
这个问题已经有了答案:
- Console.ReadLine(“Default Text Editable Text On Line”) 2 answers
- 控制台。ReadLine(“在线上的默认文本可编辑文本”)2答案
I have multiple I/O tasks that I want to do with a console:
我有多个I/O任务,我想用控制台完成:
- Print out standard, non-editable text (
Console.WriteLine()
) - 打印出标准的、不可编辑的文本(Console.WriteLine()))
- Print out text that the user can edit (
?
) - 打印出用户可以编辑的文本(?)
- Allow the user to type, and be able to output text via the two methods above (
?
)- It would be nice if I could do password masking too.
- 如果我也能做密码屏蔽就好了。
- 允许用户输入,并能够通过上面的两个方法(?)输出文本如果我也能做密码屏蔽就好了。
Anybody have any solutions?
谁有解决方案吗?
4 个解决方案
#1
5
Edit text like in a console-based text editor?
编辑文本,像在基于控制台的文本编辑器?
I think all that you need is in the Console class, have a look at its members:
我想你所需要的只是控制台类,看看它的成员:
http://msdn.microsoft.com/en-us/library/system.console.aspx
http://msdn.microsoft.com/en-us/library/system.console.aspx
#2
2
Maybe you could give curses a try, there is a C# wrapper avaiable. Didn't tried it myself, though...
也许你可以尝试一下,有一个c#包装器。我自己也没试过,不过…
#3
2
Party like it's 1988 with Mono's getline. http://tirania.org/blog/archive/2008/Aug-26.html
就像1988年Mono的getline派对一样。http://tirania.org/blog/archive/2008/aug - 26. - html
#4
0
Answer already submitted but the below code may be help
已经提交了答案,但是下面的代码可能会有所帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static int i = 0;
public static string[] S = new string[] { "A", "B", "C", "D", "E", "F" };
static void Main(string[] args)
{
Console.Write("Please Select : "+S[i]);
ConsoleKeyInfo K = Console.ReadKey();
while (K.Key.ToString() != "Enter")
{
Console.Write(ShowOptions(K));
K = Console.ReadKey();
}
Console.WriteLine("");
Console.WriteLine("Option Selected : " + S[i]);
Console.ReadKey();
}
public static string ShowOptions(ConsoleKeyInfo Key)
{
if(Key.Key.ToString() == "UpArrow")
{
if (i != S.Length-1)
return "\b\b" + S[++i];
else
return "\b\b" + S[i];
}
else if (Key.Key.ToString() == "DownArrow")
{
if(i!=0)
return "\b\b" + S[--i];
else
return "\b\b" + S[i];
}
return "";
}
}
}
#1
5
Edit text like in a console-based text editor?
编辑文本,像在基于控制台的文本编辑器?
I think all that you need is in the Console class, have a look at its members:
我想你所需要的只是控制台类,看看它的成员:
http://msdn.microsoft.com/en-us/library/system.console.aspx
http://msdn.microsoft.com/en-us/library/system.console.aspx
#2
2
Maybe you could give curses a try, there is a C# wrapper avaiable. Didn't tried it myself, though...
也许你可以尝试一下,有一个c#包装器。我自己也没试过,不过…
#3
2
Party like it's 1988 with Mono's getline. http://tirania.org/blog/archive/2008/Aug-26.html
就像1988年Mono的getline派对一样。http://tirania.org/blog/archive/2008/aug - 26. - html
#4
0
Answer already submitted but the below code may be help
已经提交了答案,但是下面的代码可能会有所帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static int i = 0;
public static string[] S = new string[] { "A", "B", "C", "D", "E", "F" };
static void Main(string[] args)
{
Console.Write("Please Select : "+S[i]);
ConsoleKeyInfo K = Console.ReadKey();
while (K.Key.ToString() != "Enter")
{
Console.Write(ShowOptions(K));
K = Console.ReadKey();
}
Console.WriteLine("");
Console.WriteLine("Option Selected : " + S[i]);
Console.ReadKey();
}
public static string ShowOptions(ConsoleKeyInfo Key)
{
if(Key.Key.ToString() == "UpArrow")
{
if (i != S.Length-1)
return "\b\b" + S[++i];
else
return "\b\b" + S[i];
}
else if (Key.Key.ToString() == "DownArrow")
{
if(i!=0)
return "\b\b" + S[--i];
else
return "\b\b" + S[i];
}
return "";
}
}
}