How to customize the backcolor and forecolor of text in WinForms SyntaxEditor (EditControl)?
Customize the backcolor and forecolor
In Edit control, it is possible customize the Selected text Backcolor and Forecolor by using 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.s
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
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