User Inteface problem: A way to get MDI Children to show up in taskbar?

后端 未结 3 1430
春和景丽
春和景丽 2021-01-27 09:27

I\'d like your advice on the following issue: We are studying different User Interface solutions for an Windows Forms application we are developing and we have come to the concl

3条回答
  •  孤独总比滥情好
    2021-01-27 10:08

    By design, children of an MDI form do not show up in the Taskbar. It's best to stick to this principle.

    On Windows 7, you can add a 'thumbnail' for an MDI child to the task bar but this functionality is not available directly in .net. You can check MSDN for the additional APIs.

    There is a work-around, though: when selecting a form you can detach it from the MDI parent. You have to make sure that it is re-attached when a new child form is selected. Add the following code to your MDI container form:

        private Form focusedChild;
    
        private void CreateWindow()
        {
            Form window = new Form();
            window.GotFocus += new EventHandler(Child_GotFocus);
            window.Show();
        }
    
        void Child_GotFocus(object sender, EventArgs e)
        {
            Form window = sender as Form;
    
            if (null != window)
            {
                if (focusedChild != null && window!=focusedChild)
                {
                    focusedChild.SuspendLayout();
                    focusedChild.MdiParent = null;
                    focusedChild.WindowState = FormWindowState.Minimized;
                    focusedChild.ResumeLayout();
                }
    
    
                window.SuspendLayout();
                window.MdiParent = this;
                window.WindowState = FormWindowState.Maximized;
                window.ResumeLayout();
    
                focusedChild = window;
            }
        }
    

    I would not recommend this, however. Stick to the default behaviour, or look at the Windows 7 thumbnails if your app will run on Windows 7.

提交回复
热议问题