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 属性并将对一个表单的实例的引用传递给另一个表单的实例一样简单形成。对于更复杂的项目,这种违反严格封装的样式和松散耦合可能会增加代码的意外复杂性并引发错误,因此封装良好的解决方案将是优惠。 另请参阅: en.wikipedia/wiki/Accidental_complexity [ ^ ], en.wikipedia/wiki/Loose_coupling [ ^ ]。
更多推荐
如何将数据发送回main
发布评论