Reputation: 8131
In MDI application which event can the child Form class use to detect when the application becomes active?
I tried Form.Acivated event but it occurs only when the form is activated and doesn't when the application gets focus.
Upvotes: 1
Views: 414
Reputation: 941455
It is the MDI parent form that gets the Activated event. You can subscribe to the event in your child form's Load event. Be careful, you have to make sure you unsubscribe the event when the child gets closed or you'll leak the child form instance. Make it look like this:
protected override void OnLoad(EventArgs e) {
var main = this.MdiParent;
main.Activated += main_AppActivated;
this.FormClosed += (o, ea) => main.Activated -= main_AppActivated;
}
void main_AppActivated(object sender, EventArgs e) {
// Etc...
}
Upvotes: 2
Reputation: 61795
While WPF has such a notion, WinForms does not to the best of my knowledge; you'd need to use Form-level events (like GotFocus from the earlier answer).
Upvotes: 1