How to select again the previously selected text after changing its case in WinForms SyntaxEditor (EditControl)?
Select the text
The SetSelection() method is used to select the text in EditControl. We need to invoke SetSelection() method after converting the case of the SelectedText.
C#
//Selecting the text after converting to lowercase string lowerCaseStr; lowerCaseStr = this.editControl1.SelectedText.ToLower(); this.editControl1.SelectedText = lowerCaseStr; this.editControl1.SetSelection(col - lowerCaseStr.Length, this.editControl1.CurrentLine, col, this.editControl1.CurrentLine); //Selecting the text after converting to uppercase string upperCaseStr; upperCaseStr = this.editControl1.SelectedText.ToUpper(); this.editControl1.SelectedText = upperCaseStr; this.editControl1.SetSelection(col-upperCaseStr.Length, this.editControl1.CurrentLine, col, this.editControl1.CurrentLine);
VB
`Selecting the text after converting to lowercase Dim lowerCaseStr As String lowerCaseStr = Me.editControl1.SelectedText.ToLower() Me.editControl1.SelectedText = lowerCaseStr Me.editControl1.SetSelection(col - lowerCaseStr.Length, Me.editControl1.CurrentLine, col, Me.editControl1.CurrentLine) `Selecting the text after converting to uppercase Dim upperCaseStr As String upperCaseStr = Me.editControl1.SelectedText.ToUpper() Me.editControl1.SelectedText = upperCaseStr Me.editControl1.SetSelection(col-upperCaseStr.Length, Me.editControl1.CurrentLine, col, Me.editControl1.CurrentLine)