Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi all visitors.
I have created one form on Access and on that form i drop some textboxes and when i run that form, i can press Enter Keyboard and the cursor will place with other textbox.
But in VB.NET,When i press Enter Keyboard the cursor still place with the old textbox

Anyone know how vb.net can press Enter keyboard and place cursor on other textbox like Access?

Best Regards,
Posted
Updated 25-Jul-11 19:12pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Jul-11 1:34am    
Tag it! WPF, WinForms, what?
--SA

you write code in in textbox keypress event:-
if(e.keychar==13)
{
//write code for focus next code
}
 
Share this answer
 
Be careful: what you describe is expected behavior, so modification of this behavior can make some confusions.

Text box cursor is shown according to current keyboard focus. At the same time, it may make sense. To detect Enter, handle the event KeyDown on each control you need to pass keyboard focus. The event handler should focus the next control using Control.Focus.

I do not provide exact MSDN links and fully qualified type names because you not tag the UI library you want to use. My advice works for WPF Control and System.Windows.Form.Control and TextBox, but the name spaces are different.

You should prefer the following schema: create one single event handler of all such control and the table of focus transitions. You can find out which control got the key Enter from the parameter object sender, passed to the event handler. The transition table should define next control from the currently focused control.

—SA
 
Share this answer
 
Comments
soeun tony 26-Jul-11 21:08pm    
Thanks for your reply
I'll try to follow your idea
Thanks
use this on textBox Keypress Event
here txtUID and txtPassword are two textBoxes .here it is checking if txtUID is not blank or say if it is Filled and then Pressing Enter the Focus Will move to txtPassword
Private Sub txtUID_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUID.KeyPress
            If Asc(e.KeyChar) = Keys.Enter Then
                If txtUID.Text.Trim() <> "" Then
                    txtPassword.Focus()
                End If
            End If
        End Sub

Implement this as Per your need.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900