Create a Cross-Container Tab Index

后端 未结 2 1922
花落未央
花落未央 2021-01-26 01:28

I\'m facing a little problem I can\'t seem to solve. The problem is in an WinForm I have several containers (TabControls, Panels, ...).

The Tab-order within the controls

2条回答
  •  无人及你
    2021-01-26 02:06

    If you want to use the TAB key, it's better to not use the Leave event It will create some bad redirections if you change with your mouse for example.

    Better override ProcessCmdKey

    Here is a good solution :

     protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                bool baseResult = base.ProcessCmdKey(ref msg, keyData);
    
                //if key is tab and TextBox1 is focused then jump to TextBox2
                if (keyData == Keys.Tab && TextBox1.Focused)
                {
                    TextBox2.Focus();
                    return true;
                }
                else if (keyData == Keys.Tab && TexBox2.Focused)
                {
                    TextBox3.Focus();
                    return true;
                }
                    return baseResult;
            }
    

    Hope it helped.

提交回复
热议问题