Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, In a parent form I put a UserControl.Inside this UC is a tab control and On each tab there are some other controls.I want when focus is inside tab control, tab key changed focus inside tabcontrol tabs not other element inside parent form.

for example:on parent form there is a tabcontrol & button1.in tabcontrol,there is 2 tab,tab1 contains Control1 & Control2. tab2 contains Control3 & Control4.
when focus is On Control2 inside tab1, and I press tab,the focus will go on button1.but I want focus go on control3 inside tab2.

any suggest?thanks in advance
Posted
Updated 26-Dec-22 22:51pm

You shouldn't do that, really you shouldn't - it subverts the standard windows "flow" of focus and will probably either confuse or annoy your users. It would certainly annoy the heck out of me!

As far as I know, the only way to do it is from outside the usercontrol by detecting the focus arriving at the next control in the tab order, and moving it back into the usercontrol, or possibly by handling the TAB in the final control yourself instead of letting the system do it.
Nasty code, for a nasty user experience!
 
Share this answer
 
Comments
mit62 16-Apr-14 12:02pm    
Modify the comment. Deleted
I tried to handle tab key on last control inside tab1. but it doesn't work.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
if (this.ActiveControl.TabIndex == 2)//Control2 inside tab1
Control3.Focus();
}
return base.ProcessCmdKey(ref msg, keyData);
}
gggustafson 16-Apr-14 12:06pm    
Again, why are you not listening to OriginalGriff? Windows users expect to move from tap page to tab page by clicking on the tab page title, not by clicking on or tabbing to some control within the tab page. If I may suggest that you reconsider your design
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Right)
            {
                if (tabControl1.SelectedIndex == 0)//Control2 inside tab1
                {
                    TabPage t = tabControl1.TabPages[1];
                    tabControl1.SelectTab(t);
                    return true;
                }

               
            }
            if (keyData == Keys.Left)
            {
                if (tabControl1.SelectedIndex == 6)//Control2 inside tab1
                {
                    TabPage t = tabControl1.TabPages[5];
                    tabControl1.SelectTab(t);
                    return true;
                }

              

            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
 
Share this answer
 
Comments
CHill60 27-Dec-22 5:43am    
A code dump without commentary is not a solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900