父Windows窗体和子UserControl传递数据 [英] Parent Windows Form and Child UserControl Passing Data

查看:81
本文介绍了父Windows窗体和子UserControl传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们
我有一个父Windows窗体,一个窗体操作和一个事件,在此窗体中出现了一个用户控件,当我按下确定"按钮时,在子用户控件中,我想要将数据传输到父Windows窗体,任何人都可以帮助我在这样做
多亏了每个人.

hi guys
I have A Parent Windows Form , Form some Actions and an Event Occur in this Form an User Control Appear , in The Child User Control when a Button Ok is Pressed i want , To transfer Data To the Parent Windows Form , any one can help me in doing that
thanks to every one

推荐答案

如果该按钮位于用户控件中,则它会引发一个事件,该事件将表格中可以挂钩的args传递给数据. br/> 使用事件在表单之间传递值 [使事件变得简单 [
If the button is in the user control, have it raise an event passing the data in the args that the form can hook in to.
Pass value between forms using events[^]
Events Made Simple[^]


1.声明一个自定义EventArgs,它可以保存您希望从UserControl传递到窗体的信息.
2.在UserControl中声明一个事件,该事件接受上面声明的EventArgs.
3.使表单订阅表单的Load事件中的事件.
4.从UserControl引发事件时,使用您希望传递的信息构建自定义EventArgs的新实例,并在引发事件时将其传递给它.
5.处理UserControl事件的窗体方法将获得自定义EventArgs实例.在您的表单中使用它.
1. Declare a custom EventArgs that can hold the information you wish to pass on from the UserControl to the Form.
2. Declare an Event in the UserControl that takes in the EventArgs declared above.
3. Make the Form subscribe to the event in the Form''s Load event.
4. When raising the event from the UserControl, build a new instance of the custom EventArgs with the information you wish to pass and pass it along when you raise the event.
5. The form''s method that handles the UserControl''s event will get the custom EventArgs instance. Use it in your form.


这篇关于父Windows窗体和子UserControl传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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