-2

I have a winform application, in which from parent form I open a child form. This child form can be opened from multiple parent forms. But when opened from a specific parent form, I want a message box to display when the child form gets minimized. Basically I want to check the name of the parent form which is an .exe and display the message box. Both child and parent forms are .exe.

Nikhil Kumar
  • 117
  • 3
  • 12

1 Answers1

0
if (Application.OpenForms.Cast<Form>().Any(form => form.Name == "<YOUR_CHILD_FORM_NAME>"))
{
    Form tempForm = Application.OpenForms.Cast<Form>().FirstOrDefault(form => form.Name == "<YOUR_CHILD_FORM_NAME>");
    if (tempForm.WindowState == FormWindowState.Minimized)
    {
        // FORM IS OPEN AND ALSO IN MINIMIZE MODE
    }
    else
    {
        // FORM IS OPEN BUT NOT IN MINIMIZE MODE
    }
}
else
{
    // FORM IS NOT OPEN
}

NOTE

While opening of your child form you must have to set name of your child window like....

ChildForm cForm = new ChildForm();
cForm.Name = "<YOUR_CHILD_FORM_NAME>";
cForm.Show();
Darshan Faldu
  • 1,471
  • 2
  • 15
  • 32