将值从模态形式传递到父形式vb.net [英] Passing Values from modal form to parent form vb.net

查看:111
本文介绍了将值从模态形式传递到父形式vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将信息从vb.net winforms应用程序中的模态表单传递给父表单.

I am trying to pass information to parent form from modal form in vb.net winforms application.

1.)我创建了一个表单副本,并使用以下代码进行显示.

1.) I created a copy of a form and displayed it using following code.

dim f=new frmParent()
f.show()

2.)根据条件,frmParent上的按钮将打开模式子窗体并询问一些信息.我为此使用了以下代码:

2.) Depending on conditions a button on frmParent opens a modal child form and asks for some informations. I used following code for that:

dim f = new ChildForm()
f.showDialog()

两个代码都可以正常工作.当用户按保存子窗体时,我需要关闭childForm并使用父窗体中的用户类型值.我知道如何关闭子窗体,但不确定如何将信息从子窗体传递到父窗体.

Both code works fine. When user press saves in child form i need to close childForm and use the user types values in parent form. I know how to close the childform but not sure how to pass info from childform to parent form.

推荐答案

在childForm上具有公共属性

Have a public property on your childForm

Public Property MyData As MyType

然后,当您显示表格时可以做

Then when you show the form you can do

dim f as new ChildForm()

If f.showDialog = DialogResult.OK Then
   Data = f.MyData()
End if

如果需要允许他们再次编辑该数据,则可能还需要考虑将Data传递给对话框的构造函数.

If you need to allow them to be able to edit that data again then you might also want to consider passing in the Data to the constructor of the dialog.

这篇关于将值从模态形式传递到父形式vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆