Question

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.

Is this possible?

[edit]

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".

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.

Was it helpful?

Solution

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.

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...

OTHER TIPS

Have you tried wiring up to the form's Load event and doing the work there? (note this fires up every time you show the form...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top