KeyPress 이벤트 후에 TextBox의 내용을 계산하지만 KeyPress 이벤트 중에 작은 함수를 작성했습니다. 나는 이상하게 들린다. :)Ctrl + Z를 누른 후에 TextBox의 내용을 확인하려면 어떻게합니까?
이유는 내가 현재 프로그램에서 오류를 수정하려고하는 직장에서 프로젝트를 받았기 때문입니다.
현재 KeyPress 이벤트에서 SQL Server에 대한 검색을 트리거하는 TextBox가 있습니다. 이것은 Chr (KeyAscii)로 연결된 TextBox의 현재 내용을 검색합니다.
즉, TextBox에 Hello가 포함되어 있고 커서가 단어의 끝에 있으면 제대로 작동하지만 선택되어있는 경우 a를 누르면 Hella 대신 Helloa가 검색됩니다. 그래서 해결하려면이 나는 그것이 "케이스 (26)는"이 실행 취소 작업을 수행 할 것이라고 말했습니다 섹션에 대한
Private Function TextAfterKeyPress(Ctrl As Control, KeyAscii As Integer) As String
Dim strUnSelLeft As String
Dim strUnSelRight As String
Dim strSel As String
Dim strMid As String
With Ctrl
strUnSelLeft = ""
strUnSelRight = ""
strMid = .Text
Select Case KeyAscii
Case 1 ' Ctrl + A
' No change to text
Case 3 ' Ctrl + C
' No change to text
Case 8 ' BackSpace
If .SelStart = 0 Then
' No change to text
Else
If .SelLength = 0 Then
strUnSelLeft = Left(.Text, .SelStart - 1)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = ""
Else
strUnSelLeft = Left(.Text, .SelStart)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = ""
End If
End If
Case 9 ' Tab
' No change to text
Case 13 ' Return
' No change to text
Case 22 ' Ctrl + V
strUnSelLeft = Left(.Text, .SelStart)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = Clipboard.GetText
Case 24 ' Ctrl + X
If .SelLength = 0 Then
' No change to text
Else
strUnSelLeft = Left(.Text, .SelStart)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = ""
End If
Case 26 ' Ctrl + Z
Case 27 ' Esc
' No Change to text
Case 137, 153, 160, 169, 188, 189, 190, 215, 247 ' Disallowed Chars
' No Change to text
Case 128 To 255 ' Allowed non standard Chars
strUnSelLeft = Left(.Text, .SelStart)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = Chr(KeyAscii)
Case 32 To 127 ' Standard Printable Chars
strUnSelLeft = Left(.Text, .SelStart)
strUnSelRight = Right(.Text, Len(.Text) - (.SelStart + .SelLength))
strMid = Chr(KeyAscii)
Case Else
End Select
TextAfterKeyPress = strUnSelLeft & strMid & strUnSelRight
End With
End Function
이제 다음과 같은 기능을 마련하고있다
다음 검색은하지 않습니다 올바르게 다시 작동하십시오.
Ctrl + Z 키를 눌렀을 때 TextBox의 내용이 무엇인지 알아낼 수있는 방법이 있습니까? TextBox의 내용이 변경되기 전에 KeyPress 이벤트가 발생하므로 정확한 검색을 수행 할 수 있도록 실행 취소 버퍼에있는 항목을 찾아야합니다.
누구나 올바른 방향으로 나를 가리킬 수 있습니까?