3

我有一个显示覆盖表单的 Windows 窗体:

private void ShowWait()
{             
    frmOverlay = new Base.frmOverlay("Please Wait...");
    frmOverlay.Show(this);
}

这个frmOverlay表单同时显示它在中间显示另一个表单(消息表单):

private void frmOverlay_Load(object sender, EventArgs e)
{   
    frmPleaseWait = new frmPleaseWait(_text); 
    frmPleaseWait.Show(this);
}

当我最小化主窗体时,我仍然可以看到frmPleaseWait窗体,当主窗体最小化时,有没有办法可以最小化所有窗体?

4

2 回答 2

2

You could create a recursive function that will minimize all child forms.

public void MinimizeAllChildForms(Form parent)
{
    foreach(Form f in parent.OwnedForms)
    {
        f.WindowState = FormWindowState.Minimized;
        MinimizeAllChildForms(f);
    }
}

Then in your main form, call it from the Resize event.

void MainForm_Resize(object sender, EventArgs e)
{
    if (WindowState == FormWindowState.Minimized)
       MinimizeAllChildForms(this);
}

I assume you want frmPleaseWait to also minimize when frmOverlay is minimized. If you don't, then you can simply set its parent to the main form instead so that it automatically minimizes when the main form does.

frmPleaseWait = new frmPleaseWait(_text); 
frmPleaseWait.Show(MainForm);
于 2013-09-14T18:46:21.050 回答
0

您可以为 resize 事件创建一个事件处理程序并在其中最小化您的表单:

Form2 f2 = null;

private void button1_Click(object sender, EventArgs e)
{
   f2 = new Form2(); 
   f2.Show();
}

private void Form1_Resize(object sender, EventArgs e)
{
    if (WindowState == FormWindowState.Minimized)
    {
        f2.WindowState = FormWindowState.Minimized;
    }
}

将该代码添加到您的主窗体和 frmOverlay

于 2013-09-14T18:32:49.310 回答