Articles in this section
Category / Section

How to customize the backcolor and forecolor of text in WinForms SyntaxEditor (EditControl)?

1 min read

Customize the backcolor and forecolor


In Edit control, it is possible to customize the Selected text Backcolor and Forecolor by using a property named SelectedText and functions named RegisterBackColorFormat and SetSelectionBackColor.

 

RegisterBackColorFormat - To specify required color format.

SetSelectionBackColor - To customize Back color to all the selected text.

SelectedText - To find the selected text.

 

Following code snippet helps to achieve this requirement.

C#

//Find the Selected text and highlight it.
IBackgroundFormat format =
editControl1.RegisterBackColorFormat(Color.Yellow, Color.Green);
if (this.editControl1.SelectedText != null)
 {
   for (int i = 0; i < this.editControl1.Lines.Count(); i++)
     {
       if (this.editControl1.FindText(this.editControl1.SelectedText))
         this.editControl1.SetSelectionBackColor(format);
     }
 }

 

VB

‘Find the Selected text and highlight it.
Dim format As IBackgroundFormat = editControl1.RegisterBackColorFormat(Color.Yellow, Color.Green)
If Me.editControl1.SelectedText IsNot Nothing Then
   For i As Integer = 0 To Me.editControl1.Lines.Count() - 1
       If Me.editControl1.FindText(Me.editControl1.SelectedText) Then
         Me.editControl1.SetSelectionBackColor(format)
       End If
   Next
End If

                             

                                                    Find and highlight the selectedtext in EditControl   

Figure 1. Find and High Light the SelectedText in Edit control with Image.

Samples:

C#: Find and High Light the Selected Text C#

VB: Find and High Light the Selected Text VB

Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/appearance#selection-color-customization

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