|
-
Jul 21st, 2010, 01:07 PM
#1
Thread Starter
Frenzied Member
Imitating Console.ReadLine() with a RTB & TXT
I have two controls on a windows form.
rtbOutput = RichTextBox
txtInput = TextBox
When the KeyDown event is triggered, if e.Keycode == Keys.Enter then a combination of a Switch block and if statements are used to process what the user entered in the textbox (txtInput). If for example it equals "exit" then the application will exit: Application.Exit();
If it were another command for example 'time', then "The time is ...." would be appended on a new line of rtbOutput. However how would I create my own version of Console.ReadLine()? For example when the user types 'exit', instead of just exiting the application, a new line is added to rtbOutput: "Are you sure you would like to exit? (Y/N)". Then the user has the option of typing y/n to exit or not exit the application.
This is simple in a Console application.
Code:
If(Console.ReadLine() == "exit"){
Console.WriteLine("Are you sure you would like to exit?");
If(Console.ReadLine() == "n"){
return;
}
Application.Exit();
}
When it comes to using a richTextBox and a textBox how can I 'Read' the next line the user enters and continue with my if statement, processing the response, just like I would do with a console application?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|