1 Public Class KeyBinder 2 Public Sub BindControl(ByRef CControl As TextBox) 3 AddHandler CControl.KeyDown, AddressOf TextKeyDown 4 End Sub 5 6 Private Sub TextKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 7 MsgBox(sender) 8 Dim txtControl As TextBox = CType(sender, TextBox) 9 If e.KeyCode = Keys.A AndAlso (e.KeyData And Keys.Control) Then 10 '全选 11 txtControl.SelectAll() 12 End If 13 e.SuppressKeyPress = True 14 End Sub 15 End Class
Public Class KeyBinder Public Sub BindControl(ByRef CControl As TextBox) AddHandler CControl.KeyDown, AddressOf TextKeyDown End Sub Private Sub TextKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) MsgBox(sender) Dim txtControl As TextBox = CType(sender, TextBox) If e.KeyCode = Keys.A AndAlso (e.KeyData And Keys.Control) Then '全选 txtControl.SelectAll() End If e.SuppressKeyPress = True End Sub End Class