✔ 最佳答案
Basically you will need communication between the two forms.
One way to do it is to create form2 from form1, thereby creating a reference of form2 in form1. While doing this, you will also create a back-reference to form1 from form2. This will allow a two-way communication. The reference to form2 inside of form1 must be created as a class variable, and outside of all sub-programs.
The integer variable x will not be accessible if it was created inside of a sub program. So, again, you would put x outside of subprograms to make it a class variable, and thus accessible to form2. Putting public instead of dim will ensure it is accessible by everyone.
Here is an example where form1 has a button to create form2, and form2 has a button to read the value of x in form1 and put it in textbox1.
If you need more information, PM me your e-mail address. Yahoo limits the size of supplementary answers and will probably not be sufficient.
Here's the example code for form1, hope it is not too modified by Yahoo:
Dim myForm As Form2
Public x As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If myForm Is Nothing Then
myForm = New Form2()
myForm.myParent = Me
End If
x = x + 1
TextBox1.Text = myForm.TextBox1.Text
myForm.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x = 10
End Sub
Here's the code for form2:
Public myParent As Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "" & myParent.x
End Sub