由控件或其父控件调用的事件

发布于 2024-12-20 11:54:15 字数 79 浏览 3 评论 0原文

如果 win 窗体上的组框中有一个按钮,并且当“单击”事件发生时,那么实际上是谁在调用该事件。它是按钮控件还是它的父控件,即 GroupBox。

If there is a button within a group box on a win form, and when the "click" event occurs, then who is actually calling the Event. Is it the button contorl or its parent i.e. GroupBox.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长不大的小祸害 2024-12-27 11:54:15

如果您编写了本机 Windows GUI 程序,那么收到单击消息的将是组框。按钮向其父母发送通知。但在 Winforms 中,这会通过子类化和让容器窗口将消息反射回子控件来重新路由。

事件总是起源于控件。他们的 OnClick() 方法在点击的情况下。然而,您仍然在更高级别的窗口中处理该事件。通常是表单,而不是组框。事件处理程序的 sender 参数传递对控件的引用。与本地方式相比,可以选择处理事件的确切位置是一个主要优势。它使控件具有高度适应性和可组合性。

If you'd have written a native Windows GUI program then it would be the group box that got the click message. Buttons send notification to their parents. But that gets re-routed in Winforms, both through sub-classing and having the container window reflect messages back to the child control.

Events always originate at the control. Their OnClick() method in case of a click. You however still handle the event at a higher level window. Typically the form, not the groupbox. The sender argument of the event handler passes a reference to the control. Having a choice over exactly where you handle the event is a major advantage over the native way. It makes controls highly adaptable and composable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文