|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
How to use enter key to move in next control
Hi,
My problem is when user press enter key on vb form then curser move to next control. suppose i press enter key on textbox1 then my control moves to textbox2. sample code private sub text1_keypress(---) if keyascii=13 then text2.setfocus end if end sub but if there is 50 controls on my form then i dont like to write code on each control's keypress event. help me by giving some short code for it |
|
#2
|
|||
|
|||
|
Key Preview
On each form you have a keypreview option, which can be set to true. Then in the keypress event of the form
if it = chr(13) then you move to the next control, or better yet, replace the keypress with a tab keystroke. Hope that helps! |
|
#3
|
|||
|
|||
|
replaced enter ascii val with tab but doesn't work
thanks for u'r reply. That's what exactly i want
but i wrote the following code Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB KeyAscii = 9 End If End Sub but this code does not move cursor from one text box to another textbox.i make forms keypreview to true.I dont want to move focus manually . Above method is best but not working plse do some needful. |
|
#4
|
|||
|
|||
|
replaced enter ascii val with tab but doesn't work
thanks for u'r reply. That's what exactly i want
but i wrote the following code Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB KeyAscii = 9 End If End Sub but this code does not move cursor from one text box to another textbox.i make forms keypreview to true.I dont want to move focus manually . Above method is best but not working plse do some needful. Quote:
|
|
#5
|
|||
|
|||
|
did you find a solution
hey
i am wondering if you found the answer to your question posted here because i am trying to do the same thing please post your code for me if you found the solution thanks for your time regards madhdhi Quote:
|
|
#6
|
|||
|
|||
|
Hi ! try this it works
set keypreview option true in u r form,
Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then sendsKeys vbtab End If End Sub i hope it will work in your form..! |
|
#7
|
|||
|
|||
|
thanks
Thanks so much.....
but would it work if there are more than one form should i put it on the module |
|
#8
|
|||
|
|||
|
Yes! put it in a module
Code a function like this )in module)
Public Function TabControl(key As Integer) If key = 13 Then SendKeys vbTab End If End Function Pass the keyascii from the form keypress ecent Private Sub Form_KeyPress(KeyAscii As Integer) TabControl (KeyAscii) End Sub |
|
#9
|
|||
|
|||
|
..
..
Last edited by Arjun : October 20th, 2004 at 10:19 PM. Reason: .. |
|
#10
|
||||
|
||||
|
On using the enter key to move between controls...
I had this problem, and have found (finally) a solution that works:
PrivateSub Form1_KeyDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyEventArgs) HandlesMyBase.KeyDown If e.KeyCode = 13 Then SendKeys.Send("{TAB}") EndIf EndSub Of course you still have to set the KeyPreview property on the form to True. I hope this is helpful! Note: This code is for VB.Net |
|
#11
|
|||
|
|||
|
Hi!!.. I dont think that send keys is such a good idea bacause if there would be some other applications which are active at that time, the sendkey would be sent to that particular app.
The best thing for u to do is Arrange all textboxes in array. (Put values on the INDEX of 50 controls, and add code to only one event.. let's say Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) If Keyascii= 13 then Text1(Index + 1).Setfocus End if End Sub Just be sure that you arange all the Indexes of the controls, in the order of focus.. Hope this is cool!!! Just Be! Demystify |
|
#12
|
||||
|
||||
|
Quote:
Great idea, but does that mean I need to insert this code in every KeyPress event of every text box? Good thought though... I will have to test that further and see if the send keys creates a problem. I guess I wanted a short way to do it, what can I say? ![]() |
|
#13
|
|||
|
|||
|
Quote:
But Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer) means that you make an array of Textboxes, in this case Text1(), so just 1 keypress method is needed. |
|
#14
|
|||
|
|||
|
Quote:
Hi, No you would only insert that code in one Keypress event even if you have 50 controls.. because they are considered as one because of the Array nature of the controls.. If All 50 controls are set as array controls like Text1(0),Text1(1),Text1(2), etc.. Then these Textboxes refers to only one Event.. Try creating 4 textboxes which are arrays.. whichever control you would write code to, it would open to only one procedure. Keep cool! Demystify ![]() |
|
#15
|
|||
|
|||
|
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then '13 FOR ENTER & 9 FOR TAB SendKeys "{TAB}" End If End Sub set keyPreview of form to TRUE. and still you are not getting the focus on next textbox then check tabindex property of textbox on which you want to move cursor. if it work then say thanx |