【问题标题】:VB.NET Pass Data Between Forms. How to catch the result of Dialogresult.OkVB.NET 在表单之间传递数据。如何捕捉 Dialogresult.Ok 的结果
【发布时间】:2014-04-23 16:03:10
【问题描述】:

我正在尝试从使用 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

我不能只是将此代码粘贴到任何地方。我要制作一个公共子来粘贴此代码还是有其他方法。我只想在对话框结果正常后立即开始从子窗体中读取数据

【问题讨论】:

  • 您不需要在代码中使用Me.DialogResult = DialogResult.Ok,您可以在设计器中为对话框表单中的每个按钮进行设置。

标签: vb.net forms dialog showdialog


【解决方案1】:

这取决于您希望如何显示您的子表单。您想通过单击按钮来显示它吗?如果是这样,您可以将代码放入按钮单击事件处理程序中:

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

【讨论】:

  • 感谢您的回复。我想在用户在 SubForm 中按下 ok 后立即显示我希望是否有一种方法可以在不使用太多公共字符串的情况下做到这一点
  • 不,我的意思是 SubForm 本身是如何显示的?
  • 即是什么导致它显示?当用户单击主窗体上的按钮时,它会显示吗?
  • 当用户按下主窗体上的按钮时显示子窗体
  • 然后将您的代码放入该按钮的事件处理程序中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多