天下一家·MJ

博客园 首页 新随笔 联系 订阅 管理
 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

  

posted on 2014-10-18 23:45  天下一家·MJ  阅读(497)  评论(0编辑  收藏  举报
友情链接Tkin的技术博客