I have a form1 that opens form2 as a “fake popup”
this.enabled = false;
MyForm2 myform2 = new MyForm2();
myform2.Show();
myform2.BringToFront();
When i dispose form2 i enable form1 back.
Now if the user minimizes both forms, and then clicks on form1, form1 will pop in his disenabled state.
I need to pop form2 insted.
So I created a static class to hold my last active form. On load of form2(or any other form) i save my last active form.
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
MyStaticClass.lastForm = this;
}
In form1(and other similar forms) i use:
protected override void OnGotFocus(System.EventArgs e)
{
base.OnGotFocus(e);
if (!this.Enabled && MyStaticClass.lastForm!= null && MyStaticClass.lastForm != this)
{
MyStaticClass.lastForm.Show();
MyStaticClass.lastForm.BringToFront();
MyStaticClass.lastForm.Activate();
}
}
OnGotFocus gets executed and my show/activate etc does too, but form2 never pops up. What am I doing wrong?
Thank you,
gg
You are “showing” and “activating” your form, the problem is it’s still minimized. Change the WindowState to Normal.