multiple occurences of HandleCreated for a single control

Posted by Asher on Stack Overflow See other posts from Stack Overflow or by Asher
Published on 2008-12-24T14:47:31Z Indexed on 2010/03/13 8:05 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

I’m using control that needs to be register to asynchronous events. The events will be raised in the UI thread using the ISynchronizeInvoke interface implemented by WinForms controls

I can’t register to the event at the constructor because it will allow calling the event handler before the control is fully created. during which calls to ISynchronizeInvoke are not allowed.

Solution to that problem is to use the perform the asynchronous event registration from an event handler to the HandleCreated instead of registering from the constructor.

however, this poses another issue, in some scenations the HandleCreated event is raised multiple times as result of change at the control state. For example, each changing of the “RightToLeft” property causes a WMCreate message that cause raising the “HandleCreated” event.

How can I prevent the multiply times of event rising? Is there is another way to know when the control is created and display for the first time?

I can keep a boolean flag in the HandleCreated, however it feels like a hack and I am wondering if there is a better way to handle this issue.

© Stack Overflow or respective owner

Related posts about winforms

Related posts about c#