使用接受按钮运行PUBLIC SUB [英] Running a PUBLIC SUB with ACCEPT BUTTON

查看:67
本文介绍了使用接受按钮运行PUBLIC SUB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道是否可以使用ACCEPT按钮来运行我创建的PUBLIC SUB,而无需使用按钮来运行PUBLIC SUB.

因此,代替:

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:

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:

Private Sub textSearch_Click(sender As System.Object, e As System.EventArgs) Handles textSearch.Click
    textSearch.Text = ""
    AcceptButton = search_sub()
End Sub

注意:search_sub()是按钮当前在单击时运行的PUBLIC SUB .

这里的想法是,在搜索框中输入内容后,您可以按ENTER键,而无需任何可见或完全没有搜索按钮.

非常感谢,
Tom.

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.

推荐答案

要为按按钮搜索"编写单独的代码,只需在TextBox KeyDown事件上编写代码,然后检查是否按了Enter键.如果用户按Enter键然后执行您的代码.示例:
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 :
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


Manoj,
效果很棒,

谢谢,
汤姆.
Hi Manoj,
That works brilliantly,

Thanks,
Tom.


这篇关于使用接受按钮运行PUBLIC SUB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆