0

I am building a text based game, and thought of using a form instead of a console as i usually do. So i started rebuilding a console - i created 2 text boxes, one as output and one as input.

I got the following problem while doing this: In a console application you can use console.readline() in line.
E.g.: Dim str as String = console.readline()
now i need this effect in the form application, where i wait for the user pressing enter in the input box and getting the text he wrote.
E.g.: I ask for the character name and the user has to type it in the input box, now i need the name he typed in some way.

EDIT:

i guess i will need some way to wait for a event to raise without blocking the ui thread.


I appreciate any help solving this,
Mylo.

2 Answers 2

1

To use the form as a console, you need to have your readLine method to wait for the event of the user hitting enter in the TextBox control, to do it without blocking the UI thread you need to use multithreading (hard) or tasks (difficult, easy with async programming), it's not an easy feat, so i think is better to use an old thrustworthy System.Console for this job.

However if you want to give it a try, there are some third party controls that may do it, like this one: http://www.codeproject.com/Articles/9621/ShellControl-A-console-emulation-control, there are others in Code Project so you may want to dig deep there and find one that you like.

Edit

This is a small async loop, note that i use also await.

do
    await Task.Delay(100)
loop while (ReadingLine)
Sign up to request clarification or add additional context in comments.

4 Comments

The main thing i wanted to do is waiting for an input in the input form, and using the input in some way. I guess you mean with system.console doing the whole project in a console application? Well, i guess ill need some forms / buttons too. - If i do it async, i would need a async while/until loop which i don´t get at all :/ right?
Yes i mean a console application, and using async you will require an async loop.
googled after it, i cant seem to find anything usefull. Would it be possible you link me to a resource?
Ok this seems not to really solve my problem, i guess its more waiting for an event without blocking the ui.
0

I think you're greatly overthinking this, my friend. The textbox is called TextBox1, on default.

So, to capture the data inside the text box, you say:

Dim someIdentifier As String = TextBox1.Text

And now you've captured the data in a variable, just like when you would capture it using

Console.ReadLine()

1 Comment

Thing is after they pressed enter, the textbox gets cleared and appended to the output box. So i cant simple get the value out of it though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.