问一个FORM 间传递参数的小问题
有两个form ---form1 form2
form1 上有 控件textbox1 button1
form2 上有 控件 label1
现在需要是用户在form1的textbox1 填入名字之后,按下button1,弹出form2,form2的label1的内容为textbox1的内容
下面是我写的代码————————————————————————————
首先在form1 加入
#Region "升级支持 "
Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As Form1
Get
If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New Form1()
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set
m_vb6FormDefInstance = Value
End Set
End Property
#End Region
在form2也同理
然后
在form1的button1的click事件里写
form2.definstance.show()
然后在form2的form load 事件里写
me.label1.text=form1.definstance.textbox1.text
————————————————————————————————
运行结果是:
在form1的textbox1输入“王磊”
按button1
------正常弹出form2
但是form2的label1里面的内容是空的
请问我的代码问题在哪呢?谢谢!
[解决办法]
Dim myform As Form1 = CType(Me.Owner, form)
Dim myform As New form2
myform.Owner = Me
myform.Show()