Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

How to accept input from a textBox on a .Net Form Application

Greetings:

I have a Form application and I need to a accept input from a text box and store it in an associated variable so that I can pass the variable throughout the application.

My questions are:

1)  How do I initialize the text box so that it is empty upon launch or so that it doesn't show 'textBox1' ?
2)  When the user types in the appropriate text, how does that text get assigned to a string variable  ?
3)  In order to accept the text does the user need to hit the 'Enter' key on the keyboard ?

I'm guessing the code begins with:

void Form1::textBox1_TextChanged(System::Object * sender, System::EventArgs * e)
{
      ???
}

Thanks
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Hello!

1) You have the Text property in the Properties window. Just delete the displayed value.
2) You can use the TextChanged event, but I recomend you to use Leave instead, or Validating.
3) What means "accept" for you? No, it is not necessary...
Avatar of John500

ASKER

ghergu,

I need a little code example of how the text which is input by the user is accepted in the background.  What variable captures this input?  If I use the TextChanged() event or any other method how do I capture the input ?

Can you just leave me a simple code example and I'll close this question out.  I'm sure it can't be difficult.  I also think I prefer TextChanged() because I can see this declaration is ready for code - I just need to put something in it that works.  That's where you come in.

Thanks
Avatar of John500

ASKER

ghergu,

Any input here ?
Avatar of Flying-Kiwi
Flying-Kiwi

Umm, I've never written a C++ [rogram. I've just popped in to visit form the VB.NET forum, but the principleshould be the same:

A textbox has a property, Text. So, the value in the textbox can be gotten with TextBox1.Text

Create a string variable (sorry, I don't know how in C++), say 'name' if that's what the user will enter. then assign it to the value of TextBox1.Text, as in:

name = TextBox1.Text

...and now you can use the variable name as needed.

Hope it helps.

Let's see what a flaming I get for popping in here. He he.
(and sorry for all the typing errors. doh.)
ASKER CERTIFIED SOLUTION
Avatar of Flying-Kiwi
Flying-Kiwi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John500

ASKER

Flying-Kiwi,

Thanks !

I really should have known this.  Once you said what you did, I realized immediately.  I think the mind-block was that I expected the data had to be 'entered' first.  I forgot that by adding a button I could accomplish the same.

Incidently, this button is labeled 'OK'.  I noticed that it is only activated by selecting it with the mouse.  Shouldn't there be a property that allows the keyboard 'Enter' key to work also ?

Thanks again

Super glad I could help. My first points at Experts Exchange have come from a C++ forum. I'll break outthe champagne tonight.  lol.

For the 'Enter' key to click the button, it needs to 'have focus'. For example, you may want to check the tab order so the user can enter the info, hit the tab key once - the Okay button now has focus - then hit the Enter key to trigger the button's click event.

You can change the tab order of controls in the IDE properties window: Look for TabIndex or something similar (could be ZOrder).

Good luck!
Avatar of John500

ASKER

... looks like the tab order was already correct.  I just needed to use the tab key to set focus.  Thanks man ...