How to change Caller form's TextBox.Text

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
There are 3 forms, that is, form1, form2, form3.

form1 calls form2(as modal) and the form2 calls form3(as modal).
form2 has a TextBox.
From form3, I want to change form2.TextBox.Text.
How to do this?
 
Assuming it's the default instance of Form2 that was displayed in the first place then you can access Form2 via its default instance in Form3 as well. That's the whole point of default instances. To learn more on that subject, follow the Blog link in my signature and check out my post on Default Form Instances.

Ideally though, Form3 shouldn't even know that Form2 exists. Form3 should provide an appropriate interface for anybody to pass in the appropriate data and retrieve the appropriate data. Form2 can then display Form3, get the data from it when it closes and update its own TextBox, e.g.
Using dialogue As New SomeForm
    'Pass input.
    dialogue.SomeProperty = someValue

    If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
        'Retrieve output.
        someOtherValue = dialogue.SomeOtherProperty
    End If
End Using
Code following that pattern would appear in Form2 to display Form3. It's up to you to define the appropriate properties in Form3 to accept input and/or provide output. You might not need any input or you might use the same property for both. You might only need one property or you might need more. It all depends on the situation. In your case it sounds like no input and one output is all you need.
 
Back
Top