如何将数据发送回main_form1 ... [英] How do I send data back to main_form1...

查看:67
本文介绍了如何将数据发送回main_form1 ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello codeproject,



我一直在努力尝试在form2中获得保存按钮点击事件以包含

one将数据发送回main_form1的事件中的重要变量。

似乎TEventArgs是放置它的地方,如EventHandler和EventHandler< teventargs>中所述。文件。



但我该怎么做?所有尝试都失败了。

注意N_name是指向main_form1中的字符串的'ref'指针

(并且它在save_Btn_Click事件之外工作)。

N_name定义为 - ref string N_name,返回main_form1。



在form2中,我在活动之外发表声明:

N_name =PC_NetXXX; //工作,将数据发送回main_form1

但是在save_Btn_Click事件中尝试这样做是有问题的。



Hello codeproject,

I have been struggling with trying to get a "save button click event" in form2 to include
one important variable into the event to send data back to main_form1.
It seems that TEventArgs is the place to put it as described in the EventHandler and EventHandler<teventargs> documentation.

But how do I do that? All attempts have failed.
Note that N_name is 'ref' pointer to a string back in main_form1
(and it does work outside of the save_Btn_Click event).
N_name is defined as - ref string N_name, back in main_form1.

In form2 I have a statement outside of the event:
N_name = "PC_NetXXX"; // works, sends data back to main_form1
But trying to do it in the save_Btn_Click event is problematic.

private void save_Btn_Click( object sender, EventArgs e) // TEventArgs?
        {
            N_name = tBox_NetName.Text;  // N_name, this does not work.
        }



问题是,如何让save_Btn_Click包含N_name并将数据发送回main_form1?



非常感谢,

JimOr


Question is, how do I get the save_Btn_Click to include N_name and send the data back to main_form1?

Thanks Kindly,
JimOr

推荐答案

这是关于表单协作的热门问题。最强大的解决方案是在表单类中实现适当的接口,并传递接口引用而不是引用Form的整个实例。有关更多详细信息,请参阅我以前的解决方案:如何以两种形式复制列表框之间的所有项目 [ ^ ]。



另请参阅此处的其他解决方案讨论。如果应用程序足够简单,解决方案就像在一个表单中声明一些 internal 属性并将对一个表单的实例的引用传递给另一个表单的实例一样简单形成。对于更复杂的项目,这种违反严格封装的样式和松散耦合可能会增加代码的意外复杂性并引发错误,因此封装良好的解决方案将是优惠。



另请参阅:

http://en.wikipedia.org/wiki/Accidental_complexity [ ^ ],

http://en.wikipedia.org/wiki/Loose_coupling [ ^ ]。



-SA
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA


这篇关于如何将数据发送回main_form1 ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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