How to make Enter on a TextBox act as TAB button

后端 未结 12 2631
迷失自我
迷失自我 2020-12-25 13:10

I\'ve several textboxes. I would like to make the Enter button act as Tab. So that when I will be in one textbox, pressing Enter will move me to the next one. Could you plea

12条回答
  •  粉色の甜心
    2020-12-25 14:07

    Here is the code that I usually use. It must be on KeyDown event.

    if (e.KeyData == Keys.Enter)
    {
        e.SuppressKeyPress = true;
        SelectNextControl(ActiveControl, true, true, true, true);
    }
    

    UPDATE

    Other way is sending "TAB" key! And overriding the method make it so easier :)

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {            
        if (keyData == (Keys.Enter))
        {
            SendKeys.Send("{TAB}");
        }
    
        return base.ProcessCmdKey(ref msg, keyData);
    }
    

提交回复
热议问题