将值从子级传递到父级-reg [英] passing value from child to parent -reg

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

问题描述



我有一个带有搜索按钮的父表单.
当我单击搜索按钮时,它将显示子窗体.
从子级中选择一个值后,我会将一个值发送给父级表单.

在这里,我的代码运行良好,但是现在的问题是我得到了两种父形式,一种是有价的,另一种是无价的.

如何隐藏没有价值的表格.

如果我使用this.hide()函数,则子窗体将出现在状态栏中.

Hi,

I have parent form which has a search button.
When I click the search button it will show child form.
On selecting a value from child, I''ll send a value to parent form.

Here my code is working well but the problem is now that I''m getting two parent forms, one is with value, the other without value.

How to hide the without value form.

If i put this.hide() function my child form appears in status bar.

How do I overcome this problem?

推荐答案

好,看不到您的代码,这只是猜测,但我认为您的代码是:
子形式:
Ok, without seeing your code this is just guesswork, but I think your code is:
Child form:
ParentForm pf = new ParentForm();
pf.IWantAValue = myNewValueFromChildForm;
fp.Show();



问题在于它创建了父窗体的新实例,并将值交给它.然后显示新的父级.

您需要做的是将值交给父窗体的原始实例,而不是创建新实例.取决于显示孩子的方式-childForm.Show()或childForm.ShowDialog()-如何执行此操作会有所不同.

如果选择值时未关闭子级,则在子级"I Have A Result"中创建一个事件,并在父级中订阅该事件.

如果要关闭子项,则在子项中创建一个公共属性,然后以这种方式返回结果.



The problem with this is that it creates a new instance of the parent form, and hands the value to it. It then displays the new parent.

What you need to do is to hand the value to the original instance of the parent form, not create a new instance. Depending on how you are showing your child - childForm.Show() or childForm.ShowDialog() - how you can do this will be different.

If you are not closing the child when you select a value, then create an event in the child "I Have A Result" and subscribe to it in the parent.

If you are closing the child, then create a public property in the child and return the result that way.


这篇关于将值从子级传递到父级-reg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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