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

发布于 2024-09-28 13:48:52 字数 172 浏览 0 评论 0原文

我们知道,当一个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 技术交流群。

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

发布评论

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

评论(3

莫相离 2024-10-05 13:48:52

设计者尊重基类成员的访问修饰符。您必须将基本窗体控件的 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.

终止放荡 2024-10-05 13:48:52

您在基本表单上处理该事件并使用它来调用虚拟方法。派生的 Form 重写该方法。

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

夕色琉璃 2024-10-05 13:48:52

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

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.

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