How to make Enter on a TextBox act as TAB button

后端 未结 12 2682
迷失自我
迷失自我 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 13:51

    You can write on the keyDown of any control:

            if (e.KeyCode == Keys.Enter)
            {
    
                if (this.GetNextControl(ActiveControl, true) != null)
                {
                    e.Handled = true;
                    this.GetNextControl(ActiveControl, true).Focus();
    
                }
            }
    

    GetNextControl doesn't work on Vista.

    To make it work with Vista you will need to use the code below to replace the this.GetNextControl...:

    System.Windows.Forms.SendKeys.Send("{TAB}");
    

提交回复
热议问题