视觉继承情况下事件处理的标准方法是什么?
我们知道,当一个Form被视觉继承时,它的所有控件都在设计时被锁定。这个问题要求我们将事件处理程序放置在基本表单中。现在,如果我想将基本控件事件处理程序放置在派生窗体中,我该怎么办?
由于控件被锁定,双击控件来添加事件处理程序的方法不应该起作用。
在视觉继承的情况下,事件处理的行业标准方法是什么?
We know that when a Form is visually inherited, all of its controls are locked in design time. This problem requires that we place event handlers in the base form. Now what should I do if I want to place base-control event handlers in the derived Form?
Since the controls are locked, approach of double clicking on the control to add an event-handler should not work.
What is the industry-standard approach for event handling in case of Visual Inheritance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设计者尊重基类成员的访问修饰符。您必须将基本窗体控件的 Modifiers 属性从 Private 更改为 Protected。重新编译。现在继承的表单可以访问该控件,您可以毫无困难地覆盖属性并从设计器分配事件处理程序。
The designer honors the access modifiers on the base class members. You must change the Modifiers property of the base form's control from Private to Protected. Recompile. Now the inherited form has access to the control, you'll have no trouble overriding properties and assigning an event handler from the designer.
您在基本表单上处理该事件并使用它来调用虚拟方法。派生的 Form 重写该方法。
You handle the event on the base Form and use it to call a virtual method. The derived Form overrides that method.
另一种方法是在用户控件中添加事件(而不是虚拟方法),然后在触发内部事件时触发该事件。
Another method is to add an event in the user control (instead of a virtual method) and then fire it when the internal event is fired.