• 0

How to Simulate a Click on a Button by Pressing Enter on the Keyboard


Question

Hello,

I would like to know how to Simulate a Click on a Button by Pressing Enter on the Keyboard In VB.Net 2008. I am working on a web browser, and would like to know how to do this.

Thank You,

UnervDeveloper

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

What part of the form will be focused when the user presses enter? Whatever it is, simply add an event handler for the KeyDown event. Example:

	Private Sub txtAddress_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtAddress.KeyDown
		If e.KeyCode = Keys.Enter Then
			e.SuppressKeyPress = True
			btnGo_Click(sender, e)
		End If
	End Sub

In this case if you hit enter on the text box identified as "txtAddress" (address box) it will prevent the enter key from being registered and showing up in the text box. It would then call the function used by "btnGo" (button) the same as if a person were to click on it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.