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

南楼画角 提交于 2019-12-08 07:44:35

问题


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?


回答1:


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.




回答2:


You handle the event on the base Form and use it to call a virtual method. The derived Form overrides that method.




回答3:


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.



来源:https://stackoverflow.com/questions/3994772/what-is-the-standard-approach-for-event-handling-in-case-of-visual-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!