Creating a 'console application'

  • Thread starter Thread starter Marco Shaw
  • Start date Start date
M

Marco Shaw

C# novice...

Can I create a console application (think the Pine email reader or even
'edit' in DOS) where I can use my up/down/side arrows to move around the
app?

I'd want something with a simple menu system as well as popup functionality.

Any hints/pointers to get me started?

Marco
 
Hi,

I know of nothing like that, at least for .net

why would you like something like that?
 
He Marco... The answer is "of course." :-) I hate to sound like an old dude
but frankly that's how we used to write apps. I wrote DOS apps (probably
some still in use) by writing the library code for the form, menu, buttons
and other controls first. The user could drag "windows" around the DOS
screen, control background colors, play sounds and all that good stuff.

In the extreme form the fanciest UI's were called "games." :-) Consider if
they could write DOOM without the Windows GUI you must be able to generate a
text-based menu system. As you point out, EDIT still works, if it wasn't
possible then it shouldn't work.
 
C# novice...

Can I create a console application (think the Pine email reader or even
'edit' in DOS) where I can use my up/down/side arrows to move around the
app?
Yes.

Any hints/pointers to get me started?

Marco
Use elements of Console for the cursor moving bit: CursorTop,
CursorLeft, KeyInfo, ConsoleKey, KeyAvailable and Read(). You may
also need System.Threading.Thread.Sleep() to wait for a key to be
pressed.

I don't know how much of a hint you want, but don't read any further
if you don't want to see a very simple demonstration.

rossum







static void Main() {
string twentyDots = new string('.', 20);

for (int i = 0; i < 10; ++i) {
Console.WriteLine(twentyDots);
} // end for
Console.WriteLine("Use arrow keys to move or X to exit.");

// Initial position of cursor
Console.CursorLeft = 9;
Console.CursorTop = 4;

// Loop to read keyboard
bool finished = false;
ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();
do {
// Wait until key is pressed.
while (Console.KeyAvailable == false) {
Thread.Sleep(100);
} // end while

// 'true' stops key echo.
keyInfo = Console.ReadKey(true);
switch (keyInfo.Key) {
case ConsoleKey.DownArrow:
++Console.CursorTop;
break;
case ConsoleKey.LeftArrow:
--Console.CursorLeft;
break;
case ConsoleKey.RightArrow:
++Console.CursorLeft;
break;
case ConsoleKey.UpArrow:
--Console.CursorTop;
break;
case ConsoleKey.X:
finished = true;
break;
default:
break;
} // end switch
} while (!finished);
} // end Main()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top