我正在尝试从我用showdialog
打开的子表单中返回一些数据我在堆栈溢出时提到了这个问题:VB.NET Pass Data Between Forms
这是代码。我知道你在子表单上写的代码:
Public Property CustomerID as Integer
Private Sub OK_Click(s as Object, e as eventargs) Handles OK.Click
CustomerID = id 'pass the value here
Me.DialogResult = DialogResult.Ok
End Sub
但我不知道在哪里输入主窗体中的代码
If frmChild.ShowDialog = DialogResult.Ok Then
MessageBox.Show("Customer ID: " + frmChild.CustomerID)
End If
我不能将此代码粘贴到任何地方。我是否使用Public子句粘贴此代码,或者是否有其他方法。我只想在对话框结果正常后开始从子表单中读取数据
答案 0 :(得分:2)
这取决于您希望如何显示子表单。是否要通过单击按钮显示它?如果是这样,您可以将代码放入按钮单击事件处理程序:
Private Sub _showSubFormButton_Click(sender As System.Object, e As System.EventArgs) Handles _showSubFormButton.Click
Dim frmChild = New SubForm
If frmChild.ShowDialog = DialogResult.OK Then
MessageBox.Show("Customer ID: " & frmChild.CustomerID)
End If
End Sub