Passing Values from modal form to parent form vb.net

喜你入骨 提交于 2019-12-23 12:53:44

问题


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

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

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

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()

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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/7020560/passing-values-from-modal-form-to-parent-form-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!