子控件中的用户控件(Winforms)事件. [英] User Control(Winforms) events from child controls.

查看:96
本文介绍了子控件中的用户控件(Winforms)事件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,上面放置了一个FlowControlPanel,然后还有其他控件.现在,我可能已经预料到了子控件中发生的事件,这些事件也将被发送到用户控件级别进行处理.例如,当某人单击控件中的标签时,不仅应触发标签上的Click事件,而且还应触发用户控件上的Click事件.

我的意思是不仅单击了标签,而且单击了我的用户控件.也许我遗漏了一些东西,也许我输入了错误的搜索条件,但是是否总有办法让子控件的事件触发用户控件事件?

I have a User Control which I''ve placed a FlowControlPanel on, then some other controls. Now I''ve probably assumed to much in expecting events that happen to the child controls, will also be sent for processing at the User Control level. Such as when someone clicks on the label that is in the control, not just the Click event on the label should fire, but the Click event on the User Control should fire as well.

I mean not only was the label clicked, but so was my user control. Maybe I''m missing something, maybe I''ve been entering the wrong search criteria, but is there anyway to get the events of the child controls to fire the User Controls events?

推荐答案

据我所知,除了通过鼠标钩(没有必要这样做)之外,没有其他方法可以做到这一点.相反,您可以在UserControl 类中处理孩子的Click 事件(基本上应该为您提供相同的灵活性).
As far as I know, there''s no way to do this except via a mouse hook (which may be overkill for this). Instead you could handle the child''s Click event in the UserControl class (which should basically give you the same flexibility).


Windows窗体不支持事件的概念起泡,但是您始终可以将事件添加到UserControl中,将子控件的所有鼠标单击事件路由到单个事件处理程序,然后触发该事件.

问候
Espen Harlinn
Windows Forms does not support the idea of event bubbling, but you can always add an event to your UserControl, route all mouse click events for the child controls to a single event handler, and then fire the event.

Regards
Espen Harlinn


为什么要触发UserControl的click事件.而是将其所有子控件公开,以便托管表单可以挂接其事件.

当然,您可以通过使用interopservices并强制执行鼠标单击事件来执行所需的操作,但是单击事件是唯一有意义的事件,我认为您并不是真正想要的.
Why do you want the click event for the UserControl to fire. Instead, make all of its child controls public so the hosting form can hook their events.

You can, of course do what you want by using interopservices and forcing a mouse click event, but the click event is the only event that would make sense, and I don''t think you really want that.


这篇关于子控件中的用户控件(Winforms)事件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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