General information
Title:
MatchString in a TextBox
I added a property to a TextBox named MatchString at which i add a text and when you are typing if the first characters of the text you are typing match the first characters of the match string, the rest of the text is highlighted, like in Excel, and this works routine works fine, but if i write to fast it does not work.
can someone give me a better idea on how to get the same result.
Private Sub WSTextBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
Dim strText As String = MyBase.Text, intKey As Integer = e.KeyCode
If intKey = 8 OrElse (intKey GREATEREQUAL 37 And intKey <= 40) OrElse _
(intKey GREATEREQUAL 112 And intKey <= 123) OrElse (intKey GREATEREQUAL 33 And intKey <= 36) _
OrElse (intKey GREATEREQUAL 44 And intKey <= 46) OrElse intKey = 144 OrElse intKey = 145 _
OrElse intKey = 19 OrElse intKey = 20 OrElse intKey = 16 OrElse intKey = 17 _
OrElse intKey = 91 Then
Exit Sub
End If
If intKey = 13 AndAlso MyBase.SelectedText NOTEQUAL "" Then 'ENTER
MyBase.SelectionStart = MyBase.Text.Length
ElseIf intKey = 27 AndAlso MyBase.SelectedText NOTEQUAL "" Then 'ESCAPE
MyBase.Text = VB.Left(strText, strText.Length - MyBase.SelectedText.Length)
MyBase.SelectionStart = MyBase.Text.Length
ElseIf Not MyBase.DesignMode Then
If strMatchString.Trim NOTEQUAL "" AndAlso strText.Trim NOTEQUAL "" AndAlso VB.Left(strMatchString.ToLower, strText.Length) = strText.ToLower Then
MyBase.Text = strMatchString
MyBase.SelectionStart = strText.Length
MyBase.SelectionLength = strMatchString.Length
End If
End If
End Sub
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only