我们如何将数据从一个打开的表单传递到另一个表单? [英] How can we pass data from one opened form to another?

查看:70
本文介绍了我们如何将数据从一个打开的表单传递到另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何将数据从一种形式传递到Winform中另一种打开的形式?

How can we pass data from one form to another opened form in winform?

在Windows应用程序中,一种形式会打开另一种形式。当我以父母形式输入一些数据时,它将立即反映在另一个子形式中。

In a windows application one form opens another form. When I am entering some data in parent form then that will reflect in another child form immediately.

这将如何发生?

推荐答案

取决于您想要获得的幻想。

Depends how fancy you want to get.

最简单的方法就是直接调用方法。

Simplest approach is just to call methods directly.

父母

_child = new ChildForm();

然后,当您检测到更新(TextChanged,SelectedIndexChanged等)时

then, when you detect updates (TextChanged, SelectedIndexChanged etc.)

_child.UpdateData(someDataCollectedFromParent)

孩子

public void UpdateData(MyObject data)
{
    textBox1.Text = data.FirstName;
    textBox2.Text = data.SecondName;
}

除此之外,您可以建立消息传递机制或查看< a href = http://msdn.microsoft.com/en-us/library/ef2xyb33.aspx rel = nofollow>数据绑定基础结构。

Other than that, you could build your message passing mechanism or look into the DataBinding infrastructure.

这篇关于我们如何将数据从一个打开的表单传递到另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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