如何共享表单之间的数据? [英] How to share data between forms?

查看:313
本文介绍了如何共享表单之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑两种形式:Form 1和Form

Consider two forms: form1 and form2

Form1中通话窗口2

form2 frm = new form2()
frm.show

窗口2 显示了数据网格。当选择的数据,它的投产一个文本框。

form2 shows a grid with data. When data is selected, it's put into a textbox.

我需要从窗口2 Form1中的返回值时,它的关闭。

I need the return value from form2 to form1 when it's closed.

如何才能做到这一点?

推荐答案

公共属性添加到窗体2 类返回选定的项目。

Add a public property to your Form2 class that returns the selected item.

然后,替换显示() ShowDialog的调用()(阻塞的方法),并检查该属性算账。

Then, replace the Show() call with ShowDialog() (a blocking method) and check the property afterwards.

此外,重命名您的表格。

Also, rename your forms.

这篇关于如何共享表单之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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