Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm wondering if it is possible to use the ACCEPT BUTTON to run a PUBLIC SUB I have created, without using a button to run the PUBLIC SUB.

So instead of:
VB
Private Sub textSearch_Click(sender As System.Object, e As System.EventArgs) Handles textSearch.Click
    textSearch.Text = ""
    AcceptButton = btnSearch
End Sub
Maybe something along the lines of:
VB
Private Sub textSearch_Click(sender As System.Object, e As System.EventArgs) Handles textSearch.Click
    textSearch.Text = ""
    AcceptButton = search_sub()
End Sub
Note: search_sub() is the PUBLIC SUB that the button currently runs on click.

The idea here is that you can press ENTER after input in the searchbox without havin a search button either visible or there at all.

Many thanks,
Tom.
Posted
Updated 24-Dec-11 6:12am
v2

Insted of writing seperate code for Search on Button just write your code on TextBox KeyDown Event and Check Whether Enter Key Pressed or Not.If User Press Enter Key then Execute Your Code.Example :
VB
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            'Your Code goes Here
        End If
    End Sub
 
Share this answer
 
v2
Hi Manoj,
That works brilliantly,

Thanks,
Tom.
 
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