0

Hi,

I am pretty new to C# and cannot seem to find an answer to this question after 10 minutes google searching. What is the best way to suspend a program to wait for input on a textbox, specifically enter. I think my current problem is that I am coding inside the form, so if I want to do a block on it (like a semaphore) I end up suspending the textbox inside the form as well. I attempted to make a thread that would handle the main execution, but it does not have direct access to the form since it did not create it. I am basically looking for something with similar logic to cin in c++. Thanks.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ddanbe
0

It appears your are used to procedural programming (where each line is executed one after another, input stops the system, etc.) What you need to learn is event driven programming (which is what all GUI based systems are doing).

You don't 'stop' the execution. You set up the GUI and you attache your code to 'events' such as 'button click', 'mouse over'. In your case, you'd want something to indicate that the user is done with entering text in the textbox (Enter key pressed, focus changes out of the textbox, submit button) then enter the code you need to handle the input in that event.

I've attached a small program that shows this. You'll want to look at the Form1.cs file to see how the events are handled (the two buttons).

0

The cin "analog" in C# is Console.ReadLine.
But as you are using textboxes in a FormsApplication, you cannot use that, you have to write a ConsoleApplication.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.