Auto button press

Hello_world

New member
Joined
Jul 20, 2008
Messages
4
Programming Experience
Beginner
Hello Everyone,

I am new to VB .net, well quite new to programming per se :D.

I was able to read a book before and somehow already forgot how it was done. Anyway, I was trying to perform this task.

Let us say I am in a login screen. The focus is on the login id field. When I press the enter key, automatically, the system should know that what I want to do is click on the ok button. How can I achieve this goal of mine?

Thanks in advance.
 
FOUND the answer

Textbox has a keydown, keyup and keypress events.. I'd attach an event handler to the keyup and then check the

If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return Then DoLoginProcess()


http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx


Thank you very much for the help!

I saw a posting in the internet and his input was there is a property in the form which is "Acceptbutton". It also solved my problem.

Again thank you very much
 
AcceptButton would be best answer, for other button presses PerformClick method can be used.
 
If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Return) Then
Call okay_button_Click(New Object, New System.EventArgs)
End If

^^ On one of the key press events

If you want to run the code in a button's click event from elsewhere you should put that code into it's own sub then call the sub in the button's click event and the other location(s).

If you need a quick and dirty way of auto-clicking of a button, use it's PerformClick() method. I.E. okay_button.PerformClick()
 
Back
Top