Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!!!

I am developing a web page in VB.net.
On hitting the enter button I want to focus on the next item.

In VB6 there are events like Keypress/Keyup/Keydown/gotfocus etc..

I am unable to find such events in VB.net.

How can I use the enter key to navigate?

Thanks!!!

Ernest
Posted

Here: MSDN: Control.OnKeyPress Method [^]

You would need to override OnKeyPress, something like (C# version - I am little quick with pseudocode in C#):
C#
protected override void OnKeyPress(KeyPressEventArgs e)
{
        if (e.KeyCode == Keys.Enter)
        {
            // Do whatever you want
            e.Handled = true;
            //SendKeys.Send("{TAB}");
        }
}


All the events of Button: MSDN: Button Events[^]
 
Share this answer
 
v3
Comments
ernestmachado 23-Apr-12 0:11am    
Thank you Sandeep for the code and link.
I tried your code but it is not recognizing the KeyPressEventArgs e argument.
Is any name space needs to be included.
Sandeep Mewara 23-Apr-12 3:12am    
Did you go through the MSDN links and followed it?
Mehdi Gholam 23-Apr-12 2:35am    
The OP is looking for VB.net :)
Sandeep Mewara 23-Apr-12 3:12am    
I know. I already wrote in my answer that I was/am quick with my C# pseducode so wrote that. Gave a full reference of the MSDN links where VB.NET exampled and explanations are there.

:)
ernestmachado 23-Apr-12 3:20am    
Yea I did go through the MSDN Button events.
When it comes to Control.OnKeyPress Method, I am unable to get the System.Windows.Forms namespace. I guess I'm seariously going off track.

First of all I want some clarify that I am doing a vb.net web project and not an application.
Has the System.Windows.Forms namespace has to do something related to web applications only and not web project?
Is it that some facilities present in VB6 are available for web applications only and not web project?
VB.Net has events similar to VB. Check out http://msdn.microsoft.com/en-us/library/system.windows.forms.button.aspx[^] (scroll down towards the middle of the page).
 
Share this answer
 
Comments
ernestmachado 23-Apr-12 0:07am    
Thank you for the link. But I'm still unable to get the event I need.
VJ Reddy 23-Apr-12 19:47pm    
Good reference. 5!
Abhinav S 23-Apr-12 23:15pm    
Thanks.
Prasad_Kulkarni 28-Apr-12 0:13am    
Good links Abhinav +5!
Abhinav S 28-Apr-12 0:44am    
Thanks.
These events are on each control, just select the control you need (e.g. textbox1) and in the properties you will find the events.
 
Share this answer
 
Comments
ernestmachado 23-Apr-12 0:03am    
Thank you for your reply.
I checked in the event list of a text box but events I want are not appearing.
Do we need to import any specific namespace?
Mehdi Gholam 23-Apr-12 2:34am    
All events are displayed there, so you don't have to do anything.

What event are you looking for?
Of course VB.NET also has those events. Look at the 2 drop down menus at the top of the coding area. Left menu to select the control and the right one to choose the event.
 
Share this answer
 
Comments
ernestmachado 23-Apr-12 0:08am    
Thank you for your reply. I did try that before positing the question.
Please check Solution 3 for detail solution.
 
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