I have a main form with two child modeless forms, e.g. all of the forms can be active simultaneously:
class MainForm : Form
{
Form child1;
Form child2;
public MainForm()
{
Text = "MainForm";
child1 = new Form { Text = "Child1" };
child2 = new Form { Text = "Child2" };
child1.Show(this);
child2.Show(this);
}
}
I would like to allow the user to Alt+Tab
into all of them, but surprisingly, I found that if any of the child forms is active, the owner form cannot be selected from the Alt+Tab
menu.
All three forms show up in the list, but apparently when you select the owner window and there is an active child, the child gets selected rather than the owner. The same thing happens when selecting forms in the taskbar.
Am I missing something? I started thinking of explicitly configuring shortcut keys to allow navigating from the modeless child form to the owner window, but before doing this I wanted to confirm if there is already some built-in keyboard shortcut to do this, since I don't want to break users' expectations.
Surprisingly, I couldn't find any question mentioning this behavior, which I also found rather odd.
Setting the Owner of a Form, causes this Form to stay on top of its Owner as a non-modal Window.
If the owned Form has its
ShowInTaskbar
property set totrue
, the standardALT+TAB
orWIN+TAB
combination of keys used to iterate the opened Windows in the System, brings to front (activates) the next owned Form instead of the Owner.Which child Form is activated, it depends on the current position of the Form in the Taskbar.
If the
ShowInTaskbar
property of the children is instead set tofalse
, the Owner Form is activated.To note that if a child Form can be minimized, some awkward behaviour can be observed: Alt or Control-tabbing, cause the child Forms to appear and disappear in an unpleasant way.
Anyway, the standard combination of
CONTROL+F6
keys can be used to move the focus on the opened child Forms (and the Owner Form, in this kind of layout), also bringing them to front if necessary (if the Form is minimized).Here, overridng ProcessCmdKey, so the combination of keys is intercepted no matter what child control has captured the cursor.
The code here activates a Form pressing both
CONTROL+F6
andCONTROL+SHIFT+F6
, moving the Focus to each of the opened child Forms and the Owner. It also works when a child Form is minimized (or all the them).In the Owner Form:
In the child Forms: