John500
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_TextChange d(System:: Object * sender, System::EventArgs * e)
{
???
}
Thanks
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_TextChange
{
???
}
Thanks
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
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
ASKER
ghergu,
Any input here ?
Any input here ?
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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!
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!
ASKER
... looks like the tab order was already correct. I just needed to use the tab key to set focus. Thanks man ...
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...