比如这段代码,放在TextChanged事件中有效,在按钮中就无效了:
If Selected_Text.Trim.StartsWith("'") Then
start = _rtx.SelectionStart
_rtx.SelectionStart = First_Index
_rtx.SelectionLength = Selected_Text.Length
_rtx.SelectionColor = Color.Gray
_rtx.SelectionStart = start
Else
Dim Type_str As String() = DataTables("代码格式化嫦娥").GetComboListString("VB类型","VB类型 Is Not Null").Split("|")
Dim Key_str As String() = DataTables("代码格式化嫦娥").GetComboListString("VB关键","VB关键 Is Not Null").Split("|")
start = _rtx.SelectionStart - old_s.Length
If start < 0 Then
_rtx.SelectionStart = 0
Else
_rtx.SelectionStart - = old_s.Length
End If
_rtx.SelectionLength = old_s.Length
If Array.IndexOf(Type_str,old_s) > - 1 Then
_rtx.SelectionColor = Color.Violet
ElseIf Array.IndexOf(Key_str,old_s) > - 1 Then
_rtx.SelectionColor = Color.Blue
ElseIf IsNumeric(old_s) Then
_rtx.SelectionColor = Color.Green
Else
_rtx.SelectionColor = Color.Black
End If
_rtx.SelectionStart + = old_s.Length
End If
_rtx.SelectionLength = 0
_rtx.SelectionColor = Color.Black