4

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 (?)

Anybody have any solutions?

Community
  • 1
  • 1
Entity
  • 7,972
  • 21
  • 79
  • 122

4 Answers4

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

Gabriel Magana
  • 4,338
  • 24
  • 23
2

Maybe you could give curses a try, there is a C# wrapper avaiable. Didn't tried it myself, though...

sloth
  • 99,095
  • 21
  • 171
  • 219
2

Party like it's 1988 with Mono's getline. http://tirania.org/blog/archive/2008/Aug-26.html

kenny
  • 21,522
  • 8
  • 49
  • 87
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 "";
    }
}

}
Harsh Chaurasia
  • 109
  • 1
  • 6