When Form + Control loads, Control can subscribe to the Activate and DeActivated forms of the event.
If it is a UserControl, for this you have a Control.Load event. For CustomControl, I would have to look for it.
In any case, be sure to implement Dispose in your control to unsubscribe from events.
Just tried:
private void UserControl1_FormActivate(object sender, EventArgs e)
{
label1.Text = "Acitve";
}
private void UserControl1_FormDeActivate(object sender, EventArgs e)
{
label1.Text = "InAcitve";
}
private void UserControl1_Load(object sender, EventArgs e)
{
this.ParentForm.Activated += UserControl1_FormActivate;
this.ParentForm.Deactivate += UserControl1_FormDeActivate;
}
source
share