简体   繁体   English

当使用Ctrl + Tab在其他Mdichild形式之间切换时,如何防止某个Mdichild形式获得焦点/激活? C#

[英]how to prevent a certain mdichild form from getting focus/activation when switching between other mdichild forms using Ctrl+Tab? C#

In my mdi application i have four mdichild forms, one of them is used as a background and holding some controls.. 在我的mdi应用程序中,我有四种mdichild形式,其中一种用作背景并包含一些控件。

How to prevent this background mdichild form from getting focus/activation when switching between other mdichild forms using Ctrl+Tab? 使用Ctrl + Tab在其他Mdichild形式之间切换时,如何防止此背景Mdichild形式获得焦点/激活?

In other word how to skip this background mdi child form from the Ctrl+Tab sequence? 换句话说,如何从Ctrl + Tab序列中跳过此背景mdi子窗体? and also make its z-order to be the last one so that it doesn't hide other mdichild forms when switching between them? 并使其z顺序成为最后一个,以便在它们之间切换时不隐藏其他mdichild形式?

thanks in advance. 提前致谢。

By overriding Form.ProcessCmdKey and skip the background form. 通过重写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];
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM