If you are able to keep track of all open forms in your project, then you
can add a generic handler to their 'Activated' events and check the 'sender'
parameter to get a reference to the last activated form. You can use
'AddHandler' to add handlers dynamically, and 'RemoveHandler' to remove a
handler.
Thanks for the idea but that won't work because of forms that are
instantiated outside of my application (e.g., MessageBox or UITypeEditor
forms). Of course I could create my own form types that mimic the behavior
of these classes (in which case your idea would be possible), but the
motivation of this question was to avoid doing that.
The ActiveForm is a readonly property and it will call the
GetForegroundWindow API underlying to get the current active window, so we
did not call any .NET method to set the property, so we have no idea it has
been changed unless we monitor the property.(e.g. use a timer to monitor
the property)
Why you need the requirement, maybe we have another solution.
Thanks!
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for the info. The reason for wanting to know when ActiveForm changes
is that I need to stop a timer in a 3rd party control whenever a Dialog
window is displayed. My idea was to catch an event when ActiveForm changes
and then test ActiveForm to see if it is modal. If so, then I would stop the
control's timer until ActiveForm changed to a modless window. Using a timer
to monitor ActiveForm should work although it is not as efficient as
listening for an event.
If so, I think we have no other better solution than the Timer one. Because
the ActiveForm is a readonly property, it never call the set routine as
common property, so we have no idea when it is changed.
Hope this helps.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.