For example, I can pass a variable like this:
This demonstrates how to pass a variable to a form when the form is opened.
Expand|Select|Wrap|Line Numbers
- private void OpenForm_Click(object sender, System.EventArgs e)
- {
- // Get the value to be passed
- string parentValue = this.UserResponse.Text;
- // Create the child form and pass the value in the constructor
- this.ChildForm = new ChildForm(parentValue);
- // Show the form which will display the user's value.
- this.ChildForm.Show();
- }
Expand|Select|Wrap|Line Numbers
- public string ValueFromParent
- {
- set
- {
- this.ParentValue.Text = value;
- }
- }
Expand|Select|Wrap|Line Numbers
- private void OpenForm_Click(object sender, System.EventArgs e)
- {
- // Get the value to be passed
- string parentValue = this.dateTimePicker1.Text;
- string parentValue2 = this.dateTimePicker2.Text;
- // Create the child form and pass the value in the constructor
- this.ChildForm = new ChildForm(parentValue,parentValue2);
- // Show the form which will display the user's value.
- this.ChildForm.Show();
- }