Windows Forms, Nested TabControls with Tabs on the Groupbox Tab (w / Illustrations)

I have a form with nested tab controls. We are trying to make the application keyboard-friendly, so when you access the internal tab control, we need the Control-Tab to view the internal tabs. For the most part this works. Starting from focus in TextBox A ....

enter image description here

The Manage tab brings us to the next tab, as expected, with focus in TextBox B:

enter image description here

Fantastic, just what we wanted. If "Gamma" and "Delta" are similar, I will return to Alpha again using the Control-Tab.

However, we have several tabs where all the controls are inside group boxes. This causes all kinds of problems. If I take the same example, but put the text box inside the group box. Starting from focus in TextBox A again:

enter image description here

The control tab takes us to the next tab, as you would expect. (Curiously, the trick is nowhere to be seen ...)

enter image description here

But then the Control-tab will again lead us to ...

enter image description here

Speculation: This is due to the fact that the tab from Alpha (with group mailboxes) to Beta (with group mailboxes) left the beta version without control with focus. The focus returned to the tab control itself (AlphaBetaGammaDelta), and the Control-Tab was passed to the external tab control (OneTwoThreeFour).

Now I can fix this by catching the SelectedIndexChanged event for the inner tab control and manually focusing the first controlled focus control inside this tab every time it changes, but it seems so wrong and a maintenance headache if the controls get moved.

// Works, but I'm not crazy about it. private void tabControlABGD_SelectedIndexChanged(object sender, EventArgs e) { switch(tabControlABGD.SelectedTab.Name) { case "tp_A": tb_a.Focus(); break; case "tp_B": tb_b.Focus(); break; case "tp_G": tb_g.Focus(); break; case "tp_D": tb_d.Focus(); break; } } 

Sending the "tab order" of the form is no effect whatsoever.

What is the right way to fix this?

+5
source share
1 answer

Instead of the switch, just call the SelectNextControl method:

 void tabControlABGD_SelectedIndexChanged(object sender, EventArgs e) { this.SelectNextControl(tabControlABGD, true, true, true, true); } 
+1
source

Source: https://habr.com/ru/post/1203255/


All Articles