my screen have some textbox, and I want to goto next textbox when I press ENTER (finish input) on one textbox (same textbox in VB6 Mircosoft Forms 2.0 object library)
thanks any help!
a beginner
Printable View
my screen have some textbox, and I want to goto next textbox when I press ENTER (finish input) on one textbox (same textbox in VB6 Mircosoft Forms 2.0 object library)
thanks any help!
a beginner
VB Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles TextBox1.KeyDown If e.KeyCode = Keys.Enter Then TextBox2.Focus() End If End Sub
if I have 100 textbox, so I must write 100 event like this!
Don“t think you need 100 events like that.
You got one event which feels if the enter button is pressed down.
If enterbutton is pressed down. Just goto next textbox.
quote:
If e.KeyCode = Keys.Enter Then
TextBox2.Focus()
End If
--------------------
To something like...
if e.KeyCode = Keys.Enter Then
if TextBox1.Focus()=True Then
TextBox2.Focus()
elseif TextBox2.Focus()=True Then
TextBox3.Focus()
elseif...
...
...
Endif
Think you can do something like that
You only need one event... you also don't need to an IF else for 100 scenarios...
Set the Form's keyPreview property to True..either in code or using the Properties window...
and try this:
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Windows.Forms.Keys.Enter Then Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'selectnextcontrol(control to move from, forward=true back=false,tabstopsonly = true or false, stop at nested controls=true, go back to beginning if at end=true) End If End Sub
Have a look....
http://www.codeguru.com/forum/showth...hreadid=260066
I wouldn't rely on SendKeys...
You have few choices, SendWait probably being your best bet if you were to implement that solution. In that way, you can be 99.9% sure the message will be processed properly.
Best to rely on the parent container to handle the messaging.