You ask "what is the standard way of doing this". There is no standard way - but there are lots of ways to do this.
This is a common requirement of dialog windows - to capture data that is used by the code that displayed the dialog.
What I typically do is add a method to Form2 whose purpose is to display the form and pass back the values that the form is collecting, so to speak.
For example - in your case you are only working with a single value:
You could have a method on form2 named ShowDetail that has a signature and body as follows:
Code:
Public Function ShowDetail(ByRef value As String) As DialogResult
Me.ShowDialog()
value = TextBox1.Text
Return DialogResult.OK
End Function
You would instantiate an instance of Form2 and call its ShowDetail method. Of course, the return would not be hardcoded to OK - you would set the return based on the user clicking an OK button, or Cancel button, or whatever makes sense for your code. Your calling code would then proceed based on the return value from the ShowDetail call.
In a more complex situation, instead of passing a string variable, you would pass an object that is specificaly designed for the use of the dialog. This object would contain member fields and properties for each value of interest. It would typically also contain validation code and any other logic that allows the UI (form2) to merely act as a display and user input mechanism, without containing any business logic. As the properties are set on this object by the changing of values on the form, the object would alert the form when it is valid to enable the OK button... and so on.
Woody Z
http://www.learntoprogramnow.com