Having a form change a variable in another?

Gluttard

Active member
Joined
Jan 9, 2008
Messages
44
Programming Experience
Beginner
I want to do a kind of settings box type thing, but when I try and add a new form, it cannot change a variable in the original form.

I know I can add items to a project, so is there a specific item that allows for this?
 
The second form doesn't need to change anything in the first form. The second form merely needs to expose the data via public properties. The first form then reads that data after the second from has been dismissed.
VB.NET:
Using f2 As New Form2
    If f2.ShowDialog() = Windows.Forms.DialogResult.OK Then
        'Get data from f2, e.g.
        Dim someData As Object = f2.SomeProperty
    End If
End Using
It's up to you to declare the appropriate properties in Form2 to provide access the the data that Form1 needs.

The alternative would be for the first form to pass an object reference to the second form and have the second form set the appropriate properties of that object. The first form then gets the data from that object, which it already has a reference to.
 
Back
Top