思路很簡(jiǎn)單:通過textbox的keypress事件來捕獲鍵盤輸入,輸入輸入的是回車鍵,則調(diào)用Button_click事件
創(chuàng)新互聯(lián)是專業(yè)的云夢(mèng)網(wǎng)站建設(shè)公司,云夢(mèng)接單;提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行云夢(mèng)網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
代碼如下:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = 13 Then
call Button1_Click()
end if
End Sub
在按下事件中進(jìn)行響應(yīng),在響應(yīng)的時(shí)候進(jìn)行對(duì)按鍵的顧慮,如果是回車鍵就可以執(zhí)行函數(shù),否則按鍵都無效。
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Enter Then....................... End If End Sub
將button1作為窗體的缺省命令按鈕吧:
button1.default=true
如果沒有上面這種用法,試試
Me.AcceptButton=button1