的WinForms控制 - 后采取的行动完全初始化 [英] WinForms Control - Action after it is fully initialized

查看:127
本文介绍了的WinForms控制 - 后采取的行动完全初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要一个WinForms控制,我想添加一个处理容器已初始化控制后(或者甚至更好,母公司已初始化后,所有包含的控件)。

To a WinForms control, I would like to add a handler after the container has initialized the control (or even better, after the parent has initialized all contained controls).

原因:自定义控件有一个选项可以自动触发一个动作。它也应触发时第一次启用这个选项。

Reason: The custom control has an option to trigger an action automatically. It should also trigger when this option is first enabled.

然而,在这一点上,其他性质(如事件处理程序)尚未连接正确,并且因此影响并不如预期。

However, at this point, other properties (like event handlers) are not yet wired up correctly, and thus the effect is not as expected.

这可能吗?

据我所知,这听起来有点不寻常,所以我要澄清:

I understand that this sounds "a bit unusual", so I want to clarify:

其目的是为此组件:大概,增加一个选项,自动创建新的文件。

It is intended for this component: roughly, adding an option to "automatically create new document".

我可以在初始化期间创建DocumentInfo本身,或当属性初始化期间分配。然而,在这一点上我也应该触发事件告诉(通常父窗体),它需要更新的用户界面。该事件可能尚未接线,或其他控制arestill未初始化的,这就是为什么我想耽误大事,直到父窗体是完全初始化。

I can create the DocumentInfo itself during initialization, or when the property is assigned during initialization. However, at this point I should also fire the event to tell (usually the parent form) that it needs to update the UI. The event might not yet been wired up, or other controls arestill uninitialized, that's why I'd like to delay the event until the parent form is completely initialized.

推荐答案

我所知道的,唯一会做这个,在控制范围内直接woudl是覆盖OnVisibleChanged,并处理你的行动在第一时间显示在控制。

The only thing I know of that would do this, directly from within the control, woudl be to override OnVisibleChanged, and handle your action the first time the control is shown.

不过,我会重新考虑这个需求。这将导致你控制的行为不同于标准的Windows窗体控件。试图钩住你的行为成不规范的事件似乎是一个保养,可用性噩梦,我...

However, I would rethink the need for this. This is going to cause your control to behave differently from the standard Windows Forms Controls. Trying to hook your behavior into an event that is non-standard seems like a maintainance and usability nightmare to me...

这篇关于的WinForms控制 - 后采取的行动完全初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆