i have 1 'if' that if i key press any key(can't be a number or a letter) the last word writed(where is the text cursor) must be colored and upper cased(the 1st letter). these code works. but if i edit the text, i don't get the correct results:(
if you need more code, please ask me;)
imagine these text:
"Sub Main()
Write("hello world")
Read()
End"
the color is correct and do the 1st letter upper case. but if i put a new text before the 'End', the 'End' is always selected(like be 1st letter upper case and change the color again).
(sorry if ican't explain well, but i'm trying:()
but if i'm working(editing) in 1st line, why the text cursor, always, select the 'End' word?
maybe i need a new variable for avoid these bug, but i don't a clue:(
Code:
Private Sub RichTextBox2_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim intTextPos As Integer = 0
Dim blnIsSelectionActivated As Boolean = False
If Char.IsLetterOrDigit(Chr(e.KeyCode)) = False And (HighLightWords = True Or UpperKeyWords = True) Then
If Me.GetActualLineText = "" Or Me.GetActualLineText = " " Then Exit Sub
Dim strLastWord As String = ""
strLastWord = GetLastWord(Me.Text)
Debug.Print(strLastWord)
intTextPos = Me.SelectionStart
If IsKeyword(strLastWord).ToLower = strLastWord.ToLower Then
Me.Find(strLastWord, Me.SelectionStart, RichTextBoxFinds.MatchCase)
If HighLightWords = True Then Me.SelectionColor = ColorKeyWords
If UpperKeyWords = True Then
Me.SelectedText = UpperCaseFirstLetter(strLastWord) 'put the 1st letter, on word, in upper case way
Else
Me.SelectedText = strLastWord
End If
Me.SelectionStart += 1
If HighLightWords = True Then Me.SelectionColor = Color.Black
Me.SelectionStart = intTextPos
End Ifimagine these text:
"Sub Main()
Write("hello world")
Read()
End"
the color is correct and do the 1st letter upper case. but if i put a new text before the 'End', the 'End' is always selected(like be 1st letter upper case and change the color again).
(sorry if ican't explain well, but i'm trying:()
but if i'm working(editing) in 1st line, why the text cursor, always, select the 'End' word?
maybe i need a new variable for avoid these bug, but i don't a clue:(