简体   繁体   English

在视觉继承的情况下,事件处理的标准方法是什么?

[英]What is the standard approach for event handling in case of Visual Inheritance?

We know that when a Form is visually inherited, all of its controls are locked in design time. 我们知道,当可视地继承Form时,其所有控件都在设计时被锁定。 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? 现在,如果要将基本控制事件处理程序放置在派生的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? 在视觉继承的情况下,事件处理的行业标准方法是什么?

You handle the event on the base Form and use it to call a virtual method. 您可以在基本Form上处理事件,并使用它来调用虚拟方法。 The derived Form overrides that method. 派生的Form覆盖了该方法。

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. 您必须将基本窗体的控件的Modifiers属性从Private更改为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. 现在,继承的窗体可以访问该控件,您可以毫不费力地重写属性并从设计器分配事件处理程序。

另一种方法是在用户控件中添加事件(而不是虚拟方法),然后在触发内部事件时将其触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM