How to disable a parent form when child form is active using c#?
What you could do, is to make sure to pass the parent form as the owner when showing the child form:
Form newForm = new ChildForm();
newForm.Show(this);
Then, in the child form, set up event handlers for the Activated and Deactivate events:
private void Form_Activated(object sender, System.EventArgs e)
{
if (this.Owner != null)
{
this.Owner.Enabled = false;
}
}
private void Form_Deactivate(object sender, System.EventArgs e)
{
if (this.Owner != null)
{
this.Owner.Enabled = true;
}
}
However, this will result in a truly wierd behaviour; while you will not be able to go back and interact with the parent form immediately, activating any other application will enable it, and then the user can interact with it.
If you want to make the child form modal, use ShowDialog instead:
Form newForm = new ChildForm();
newForm.ShowDialog(this);