在vb.net中,子窗体如何向父窗体传值?

2024-12-02 20:28:12
推荐回答(2个)
回答1:

这不就是MDI吗?把主窗口的IsMdiContainer属性设置为True,然后在加载子窗口的时候加上一句:

子窗口.MdiParent = 主窗口

然后再Show就行了.

示例:

Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub

回答2:

在Form1中
Public Class Form1
Public array(0)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Forms.childform.ShowDialog()

End Sub
End Class

在childform中
Public Class childform
Private Sub childform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub TextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
My.Forms.Form1.array(0) = TextBox1.Text
Me.Hide()
End Sub
End Class
改成了双击TextBox1返回值