Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用Ctrl+在其他mdichild窗体之间切换时防止某个mdichild窗体获得焦点/激活;账单?C#_C#_.net_Winforms_Mdichild - Fatal编程技术网

如何在使用Ctrl+在其他mdichild窗体之间切换时防止某个mdichild窗体获得焦点/激活;账单?C#

如何在使用Ctrl+在其他mdichild窗体之间切换时防止某个mdichild窗体获得焦点/激活;账单?C#,c#,.net,winforms,mdichild,C#,.net,Winforms,Mdichild,在我的mdi应用程序中,我有四个mdi子窗体,其中一个用作背景并包含一些控件 当使用Ctrl+Tab在其他mdichild窗体之间切换时,如何防止此后台mdichild窗体获得焦点/激活 换句话说,如何从Ctrl+Tab序列中跳过此背景mdi子窗体?并将其z顺序设置为最后一个,以便在切换其他MDI子窗体时不会隐藏它们 提前感谢。重写Form.ProcessCmdKey并跳过后台表单 protected override bool ProcessCmdKey(ref Message msg

在我的mdi应用程序中,我有四个mdi子窗体,其中一个用作背景并包含一些控件

当使用Ctrl+Tab在其他mdichild窗体之间切换时,如何防止此后台mdichild窗体获得焦点/激活

换句话说,如何从Ctrl+Tab序列中跳过此背景mdi子窗体?并将其z顺序设置为最后一个,以便在切换其他MDI子窗体时不会隐藏它们


提前感谢。

重写Form.ProcessCmdKey并跳过后台表单

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if ((keyData & Keys.Tab) == Keys.Tab && (keyData & Keys.Control) == Keys.Control)
        {

            Form nextForm = GetNexMdiChildForm();
            if (nextForm != null)
            {
                nextForm.Activate();
                return false;
            }
        }

        return base.ProcessCmdKey(ref msg, keyData);
    }

    private Form GetNexMdiChildForm()
    {
        //get current form index
        Form currentForm = this.ActiveMdiChild;
        int currentFormIndex = Array.IndexOf(this.MdiChildren, currentForm);

        //get next form index
        int nextFormIndex = currentFormIndex + 1;
        if (this.MdiChildren.Length == nextFormIndex)
        {
            nextFormIndex = 0;
        }

        //check if next form is Form 3
        if (this.MdiChildren[nextFormIndex] == background_mdichild_form )
        {
            nextFormIndex++;
            if (this.MdiChildren.Length == nextFormIndex)
            {
                nextFormIndex = 0;
            }
        }
        return MdiChildren[nextFormIndex];
    }