How to make Enter on a TextBox act as TAB button

后端 未结 12 2670
迷失自我
迷失自我 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:53

    This is the solution I use for VB.NET

    1. Set Keypreview=True in your form properties.

    2. Put this code in form keydown event:

      If (e.KeyData = Keys.Enter) Then

      'for any multiline control, you have to exit to let multiline 'textbox intro 'keypressing makes line skips.

       If ActiveControl.Name = txtMyMutilineTextBox.Name Then Exit Sub 
      
       e.SuppressKeyPress = True
       SelectNextControl(ActiveControl, True, True, True, True)
      

      End If

    Enjoy !!!!

    Xabier Aberasturi Larruzea

提交回复
热议问题