Articles in this section
Category / Section

How to select again the previously selected text after changing its case in WinForms SyntaxEditor (EditControl)?

1 min read

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)

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied