I am creating a small program that speaks and can do minor tasks for me. I want to create a second form (Form2) in which I will type in my name and other personal info.
How can I get Form1 to read the textfields in Form2?
How can I get Form1 to read the textfields in Form2?
Presumably Form1
creates an instance of Form2
... so hold on to that instance, and expose appropriate properties on the form:
Form2 form2 = new Form2();
form2.Show(); // Or ShowDialog?
string name = form2.UserName;
The implementation of UserName
may well just fetch the value from the text field:
public string UserName { get { return userNameTextField.Text; } }
You could expose the text field directly with a property, but personally I tend to think that a form should "own" its UI, and not let other code mess with it.
See more on this question at Stackoverflow