I have multiple I/O tasks that I want to do with a console:
- Print out standard, non-editable text (
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?
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
Maybe you could give curses a try, there is a C# wrapper avaiable. Didn't tried it myself, though...
Party like it's 1988 with Mono's getline. http://tirania.org/blog/archive/2008/Aug-26.html
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 "";
}
}
}
精彩评论