道歉,如果这是新手问题,我自己就是.net上的新手。所以在这里,我有2个表格。表单1和表单2.我目前处于表单1中,我希望将值传递给表单2上的变量。这里是表单上的声明。
Public Sub Form1
Dim TempForm as Form = Form2
End Sub
Public Sub Form2
Dim Id as Integer
End Sub
所以我有可以使用TempForm访问的Form2,我知道在Form 2中有一个名为Id的变量,我想在打开之前传递一个值。请注意,我不能直接将值传递给表格2,它应该是临时表格,因为我打算使其成为动态,所以我也可以用它来打开其他表格。非常感谢!
答案 0 :(得分:2)
使用此代码:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim NewForm As New Form 'make a new form
'assign the value 50 to the variable ID
Dim IDx As New NewForm(50)
End Sub
End Class
'for new form
Public Class NewForm
Public ID As Integer
'Here's the class constructor
Public Sub New(Value As Integer)
ID = Value
'use this ID however you want
End Sub
End Class