当子项最小化时,在父表单上显示消息框

时间:2016-05-18 10:08:58

标签: c# winforms

我有一个winform应用程序,其中从父窗体我打开一个子窗体。可以从多个父表单打开此子表单。但是当从特定的父表单打开时,我希望在子表单最小化时显示一个消息框。基本上我想检查父表单的名称是.exe并显示消息框。子表单和父表单都是.exe。

1 个答案:

答案 0 :(得分: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
}
  

请注意

在打开您的子表单时,您必须设置子窗口的名称,如....

ChildForm cForm = new ChildForm();
cForm.Name = "<YOUR_CHILD_FORM_NAME>";
cForm.Show();