在表单c#之间传递数据 [英] Pass data between forms c#

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

问题描述

我有三种窗体形式。当我点击第一个表单的下一个按钮时,它应该打开第二个,我必须选择一个服务,当我点击第二个表单上的按钮时,它应该打开第三个表单。单击第三个表单的保存按钮时,它应该从第一个表单获取值,也从第三个表单获取数据。



第一个表单 - >下一个按钮 - >选择服务表单(选择服务) - >下一步按钮 - >打开服务表单 - >保存按钮 - >保存第一张表格中的数据



第一种形式有一些数据,需要与第三种形式一起保存。

我知道这是一个常见问题,但我一直都在尝试。我不知道发生了什么。请帮帮我..真的需要..

I have three windows forms. When I click the next button of first form, it should open the second in which i have to select one service and when I click the button on 2nd form it should open 3rd form. On clicking the save button of third form, it should get the value from first form and also the data from third form.

first form ->Next button-> Select Services form(select service)->Next button->Open Service form->Save button->save data from first form

There are some data in first form, which needs to be saved along with the third form.
I know this is a common question,but I tried all the way. I dont know what is happening. Please help me.. Really in need..

推荐答案

有几种方法可以做到这一点,但这样做可能不是一个好主意方式,除非你可以将日期封装在一个可以自行保存的单独的类中。

问题是,对于你的设计,这三种形式必须彼此了解,以及他们做什么,哪个从OOP的角度来看并不是一个好主意,也是一个维护PITA。



如果你可以封装它,那么第一个表单创建一个实例,填写它拥有的数据,并将其传递给第二种形式。它添加了数据,并将其传递给第三个数据。第三个添加它的数据,并告诉班级保存自己。这样,只有需要知道的类才必须知道其他类,因此可以更安全地进行更改。



另一种选择用于创建以父形式处理的事件的第二种和第三种形式 - 然后通过属性从子项获取信息并通过它自己的属性将其传递给它的父级,或者保存它是否处于顶层。

再次,这种方法将表单隔离到需要知道的基础上。
There are a couple of ways to do this, but it probably isn''t a good idea to do it your way, unless you can encapsulate the date in a separate class which can save itself.
The problem is that with your design, the three forms have to be aware of each other, and what they do, which is not a good idea from an OOPs viewpoint, and a maintenance PITA as well.

If you can encapsulate it, then the first form creates an instance, fills out the data it has, and passes it to the second form. It adds its data, and passes it to the third. The third adds it''s data, and tells the class to save itself. This way, only the classes that have need-to-know have to be aware of the others, so changes can be made with far greater safety.

The other alternative is for the second and third form to create an event which is handled in the "parent" form - which then gets the information from the child via properties and passes it up it''s parent via it''s own properties, or saves it if it is at the top level.
Again, this approach isolates the forms to a need-to-know basis.


在Windows窗体之间传递数据 [ ^ ]

在表格之间传递数据 [ ^ ]

http ://msdn.microsoft.com/en-us/library/ms171925.aspx [ ^ ]
Passing Data between Windows Forms[^]
Passing Data Between Forms[^]
http://msdn.microsoft.com/en-us/library/ms171925.aspx[^]


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

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