如何将数据从子窗体发送到父窗体. [英] how to send data from child form to the parent form.

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

问题描述

我必须要形成,所有者和孩子.我想从子级将数据发送回父表单.数据可以成功发送到父表单,但是问题是父表单在新窗口中打开..我得到两个窗口!但是我确实希望在操作后更新的窗口而不是较旧的窗口.
有人可以帮我的代码吗?
我会非常感激:)

解决方案

记住!没有人会为您编写代码.如果您需要代码方面的帮助,则需要首先下功夫,我们将..随便,
您可以 [链接与事件之间的表单间通讯 [ http://bytes.com/topic/c-sharp/answers/696941-instance-name-main-form#post2769458 [ ^ ]


i have to forms,the owner and the child. and i want to send data back to the parent form from the child.the data can successfully be sent to the parent form , but the problem is that the parent form opens in the new window.. and i get two windows !! but i really want the updated window not the older window, after the operation.
can some body help me with the code ???
i''ll be very thankful :)

解决方案

Remember! No one will write code for you. if you need help with code then you need to put your effort first then we will.. whatever,
You can go there[^] to take a look about how to Passing values between Forms.
and this Link-Inter Form Communication with Event[^] might help you


Hi Hanifuk ,
first you must create an overloaded constructor in form2 and a global object of form1 , your already existing default constructor is :


public Form2()
{
     InitializeComponent();
}


The global object and the overloaded constructor code will be :


public static Form1 Frm1 = new Form1();
public Form2(Form1 form)
{
     InitializeComponent();
     Frm1 = form;
}



Now you can set your control in form1 ''s modifier to public .

Then in the click add button event you will insert this code for opening form2 :


Form2 Frm2 =new Form2(this);
Frm2.show();



now in the form2 code you can update your control in form1.

I Hope this help you ,
Good luck


Here is example how you can send data to main form

http://bytes.com/topic/c-sharp/answers/696941-instance-name-main-form#post2769458[^]


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

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