1

下面是我的 ProcessCmdKey 代码。

Public Class EmployeeStatus

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Handl(msg, keyData, bNavi)
    End Function

    Public Function Handl(ByRef msg As Message, ByVal keyData As Keys, ByRef bNavi As BindingNavigator) As Boolean
        Try
            If keyData = (Keys.Control or Keys.S) Then
                TBSave
                Return True
            end if
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function TBSave() as Boolean
        Try
            'Some code for saving to database
        Catch ex As Exception
            msgbox(ex.message)
        End Try
    End Function

End Class

一切正常,除非它专注于文本框。它在对象中留下字符“S”。我该如何解决这个问题?

4

2 回答 2

1

我无法用第一个代码块重现它。当你说it leaves character "S" in the object你的意思是它离开了文本框?

如果 ProcessCmdKey 方法返回 true,则它已处理命令键。但是,在您编辑您的调用Handl没有返回其结果true时,只需添加 Returns 关键字来修复它

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    Return Handl(msg, keyData, bNavi)
End Function
于 2012-07-08T05:12:59.000 回答
0

我只是想通了...我只是为msg变量分配了一个空白字符串,仅此而已。

于 2012-07-20T07:47:26.193 回答