|
-
Nov 16th, 2007, 05:22 AM
#1
Thread Starter
Hyperactive Member
[2005] Accept Enter Key
I have 4 textbox in one form, If I press tab key it move to textbox1 to textbox2…
I want to this will be done press Enter Key also , Is there any properties ?
thanks
-
Nov 16th, 2007, 05:41 AM
#2
Re: [2005] Accept Enter Key
vb Code:
If e.KeyCode = Keys.Escape Then
TextBox2.Focus()
End If
Something like that in the keydown event of each textbox could work. Make sure you change the TextBox number to the one you want to set focus to.
-
Nov 16th, 2007, 06:05 AM
#3
Frenzied Member
Re: [2005] Accept Enter Key
To achieve this, I add a handler for the Text Box KeyDown events in the Form Load event as follows. This will set the handler for all text boxes on the form so that you don't have to handle each control's KeyDown event individually.
Paste this into your form and then simply set the TabStop properties of all text boxes to True and set the TabIndex properties in the order that you wish to tab.
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandlers()
End Sub
Private Sub ReturnKeyTabs(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
ReturnKeyTabs(e.KeyCode)
End Sub
Private Sub ReturnKeyTabs(ByVal KeyCode As System.Windows.Forms.Keys)
If KeyCode = System.Windows.Forms.Keys.Return Then
System.Windows.Forms.SendKeys.Send("{Tab}")
KeyCode = 0
End If
End Sub
Private Sub AddHandlers()
Try
Dim ctl As Control = Me.GetNextControl(Me, True) 'Get the first control in the tab order.
Do Until ctl Is Nothing
If TypeOf ctl Is System.Windows.Forms.TextBox Then
AddHandler ctl.KeyDown, AddressOf ReturnKeyTabs
End If
ctl = Me.GetNextControl(ctl, True) 'Get the next control in the tab order.
Loop
Catch ex As Exception
End Try
End Sub
-
Nov 16th, 2007, 06:48 AM
#4
Re: [2005] Accept Enter Key
Typically, I use the KeyPress even for enter rather than KeyDown.
-
Nov 16th, 2007, 11:32 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] Accept Enter Key
Code is working properly if only textbox is there , if i put button in between then it do not move to next textbox.
ex. textbox1,textbox1,button1, textbox3,
-
Nov 16th, 2007, 11:54 PM
#6
Re: [2005] Accept Enter Key
Person 1: I have a piece of wood and I want to chop it in half. How do I do it?
Person 2: Take your axe and swing it at the middle of the wood.
Person 1: That worked for that piece of wood. I have three more pieces of wood. How would I chop them in half too?
What do you think Person 1 should do? What works for one object will work for more than one object. You just have to do it more than once. If you've got code that works for one TextBox, don't you think it will work if you do the same thing for each of them?
-
Nov 20th, 2007, 12:28 AM
#7
Frenzied Member
Re: [2005] Accept Enter Key
 Originally Posted by Hack
Typically, I use the KeyPress even for enter rather than KeyDown.
What is the advantage of the KeyPress event over the KeyDown event?
-
Nov 20th, 2007, 12:31 AM
#8
Frenzied Member
Re: [2005] Accept Enter Key
 Originally Posted by asm
Code is working properly if only textbox is there , if i put button in between then it do not move to next textbox.
ex. textbox1,textbox1,button1, textbox3,
Set the TabStop property of the button to False or change its TabIndex property so that it does not receive focus at that point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|