Passing Value back from a form

R

robin9876

In a windows form application created in VS 2005 VB.Net I have one form
which calls another form and supplies a value. In this additional form
I need to return a value back. Below is the code to call the other
form.

Dim x As New myForm2
x.aValue = Me.TextBox1.Text
x.Show()

How can I return a value back from myForm2 back to myForm1 where the
above code is located on a button click event?
 
R

RobinS

I would set up a property on myForm1 and have myForm2 access
the property to set it.

As for the first part, you might want to consider adding a
constructor to your myForm2 that accepts a string, and pass
that value in instead of using it as a property. This makes
it more obvious if anybody else ever uses your form, that the
value needs to be (or can be) set when creating the form.

Robin S.
 
C

ClayB

Another solution is to declare aValue as a public member of Form2. Then
within Form1, you can directly reference x.aValue (provided you keep a
reference to x in scope).

================
Clay Burch
Syncfusion, Inc.
 
R

robin9876

I ended up doing that by using the showdialog option from the call in
form1 to keep the form in scope until after form2 was closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top