在.net中从父窗体调用usercontrol事件 [英] Calling usercontrol Events From Parent Form in .net

查看:78
本文介绍了在.net中从父窗体调用usercontrol事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在Windows窗体应用程序中有一个userControl,并且该userControl中包含一些事件和方法,我想从其用户控件包含它的不同父窗体中引发这些事件……..

而且我需要从用户控制包含的父表单中调用方法.........
任何人都可以帮助我........
在此先感谢...

Hi,
I have a userControl in Windows form application and the usercontrol contain some events and methods in it ,I want raise these Events from the diffrent Parent Forms whose the user control contain it........

and i need to call the methods from the parent forms which the user conrol contain............
any one pls help me........
Thanks in advance......

推荐答案

在UserControl中设置一个公共方法,该方法调用一个事件,然后从表单中调用该方法.
Make a public method in your UserControl which invokes an event, then call that method from your form.


您的问题不清楚.我认为您想以父表单处理事件,而不是从父表单引发事件.发布您的代码可能会有所帮助.但这是一个一般准则.

要以父形式处理用户控件事件,请将控件的事件连接到父形式中的方法,如下所示:
Your question is not clear. I think you want to handle the event in the parent form rather than raise it from the parent form. Posting your code might help. But here is a general guideline.

To handle user control events in the parent form, hook up the control''s event to a method in the parent form like this:
private void Form1_Load(......) {
    userControl1.MyEvent+=new EventHandler(UserControl1_MyEvent);
}

private void UserControl1_MyEvent(......) {
    //Do stuff here
}


这篇关于在.net中从父窗体调用usercontrol事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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