由控件或其父控件调用的事件
如果 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您编写了本机 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.