將button1作為窗體的缺省命令按鈕吧:
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:主機域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、汕頭網(wǎng)站維護、網(wǎng)站推廣。
button1.default=true
如果沒有上面這種用法,試試
Me.AcceptButton=button1
窗體內(nèi)檢測按鍵
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True '注冊窗體的鍵盤事件
End Sub
在TextBox1中顯示按鍵代碼
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
TextBox1.Text = Str(e.KeyCode) + vbCrLf
End Sub
窗體沒有焦點,用窗體監(jiān)測鍵盤輸入緩沖區(qū)可以解決,但這似乎可以用于監(jiān)測用戶輸入內(nèi)容,不要用于非法目的呀!所以就是知道也不會告訴你的。
Public Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim SplitStr As String = ","
Dim SelectionStart As Integer = sender.SelectionStart
Dim TextLength As Integer = sender.Text.Length
'------------------------------------------------------------------
Select Case Asc(e.KeyChar)
Case Is = 8 '"回刪"
Dim str As String = sender.text
Dim Array = Split(sender.text, ",", -1)
If sender.SelectionStart = str.Length Then
If str.Contains(",") Then
Dim text = ""
For x = 0 To UBound(Array) - 1
If text = "" Then
text += Array(x)
Else
text += "," + Array(x)
End If
Next
sender.text = text
sender.SelectionStart = text.Length
e.KeyChar = Chr(0)
End If
End If
Case Asc("0") To Asc("9") '" 0 to 9 "
e.KeyChar = e.KeyChar
Case Is = 44, 45 '","
Select Case TextLength
Case Is = 0
e.KeyChar = Chr(0)
Case Else
Select Case SelectionStart
Case 0
e.KeyChar = Chr(0)
Case 1 To TextLength - 1
If Mid(sender.text, SelectionStart, 1) = SplitStr Or Mid(sender.text, SelectionStart + 1, 1) = SplitStr Then
e.KeyChar = Chr(0)
Else
e.KeyChar = e.KeyChar
End If
Case TextLength
If Mid(sender.text, SelectionStart, 1) = SplitStr Then
e.KeyChar = Chr(0)
Else
e.KeyChar = e.KeyChar
End If
End Select
End Select
Case Else
e.KeyChar = Chr(0)
End Select
End Sub
這是我的程序中復制過來的,只能輸入數(shù)據(jù)字與逗號還有下劃線,你查一下F和J的Ass嗎是多少,改寫一下就OK
新聞標題:vb點虐
捕獲按鍵 vb獲取窗口按鈕
本文鏈接:http://m.rwnh.cn/article4/ddgdoie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、App設(shè)計、網(wǎng)站排名、服務(wù)器托管、App開發(fā)、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)