2023年4月12日 星期三

VBNET 攔截key值(二)

 Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _

                                           ByVal keyData As System.Windows.Forms.Keys) _

                                           As Boolean


    If msg.WParam.ToInt32() = CInt(Keys.Enter) Then

        SendKeys.Send("{Tab}")

        Return True

    End If

    Return MyBase.ProcessCmdKey(msg, keyData)

End Function



Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

    Dim keyCode As Keys = CType(msg.WParam, IntPtr).ToInt32

    Const WM_KEYDOWN As Integer = &H100


    If msg.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Enter _

     AndAlso Me.ActiveControl.GetType.Name = "TextBox" Then

        Me.SelectNextControl(Me.ActiveControl, True, True, False, True)

        Return True


    End If

    Return MyBase.ProcessCmdKey(msg, keyData)



End Function

沒有留言:

張貼留言