We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set different background colors for the lines in the WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl

Background color for the lines

Please refer to the code snippets below for how to set the back color for the entire line and the selected text.


private IBackgroundFormat RegisterFormat()
    Color background = Color.Empty, foreground = Color.Empty;
    if(radioButton1.Checked )
       background = radioButton1.BackColor;
    else if(radioButton2.Checked )
       background = radioButton2.BackColor;
    else if(radioButton3.Checked )
       background = radioButton3.BackColor;
    if(radioButton6.Checked )
       foreground = radioButton6.BackColor;
    else if( radioButton5.Checked )
       foreground = radioButton5.BackColor;
    else if( radioButton4.Checked )
       foreground = radioButton4.BackColor;
    bool bUseHatchFille = comboBox1.SelectedIndex > 0;
    HatchStyle style = ( bUseHatchFille )? ( HatchStyle )Enum.Parse( typeof( HatchStyle ),
comboBox1.SelectedItem.ToString() ): HatchStyle.Min;
    IBackgroundFormat format = editControl1.RegisterBackColorFormat( background, foreground, style, bUseHatchFille );
    return format;
//code for setting line backcolor for the entire line
private void button1_Click(object sender, System.EventArgs e)
    IDynamicFormat[] temp = editControl1.GetLineBackColorFormats( editControl1.CurrentLine );
    IBackgroundFormat format = RegisterFormat();
    editControl1.SetLineBackColor( editControl1.CurrentLine, true, format );
private void Form1_Load(object sender, System.EventArgs e)
    comboBox1.Items.Add( "Solid" );
    foreach( string name in Enum.GetNames( typeof( HatchStyle) ) )
        comboBox1.SelectedText = "Percent05";
        comboBox1.SelectedIndex = 0;
        editControl1.Text += "\n";
        editControl1.CurrentLine = 1;
//code to set the backcolor for a selected text
private void button2_Click(object sender, System.EventArgs e)
    IBackgroundFormat format = RegisterFormat();



Private Function RegisterFormat() As IBackgroundFormat
    Dim background As Color = Color.Empty, foreground As Color = Color.Empty
    If radioButton1.Checked Then
       background = radioButton1.BackColor
    ElseIf radioButton2.Checked Then
       background = radioButton2.BackColor
    ElseIf radioButton3.Checked Then
       background = radioButton3.BackColor
    End If
    If radioButton6.Checked Then
       foreground = radioButton6.BackColor
    ElseIf radioButton5.Checked Then
       foreground = radioButton5.BackColor
    ElseIf radioButton4.Checked Then
       foreground = radioButton4.BackColor
    End If
    Dim bUseHatchFille As Boolean = comboBox1.SelectedIndex > 0
    Dim style As HatchStyle = If((bUseHatchFille), CType(System.Enum.Parse(GetType(HatchStyle), comboBox1.SelectedItem.ToString()), HatchStyle), HatchStyle.Min)
    Dim format As IBackgroundFormat = editControl1.RegisterBackColorFormat(background, foreground, style, bUseHatchFille)
    Return format
End Function
'code for setting line backcolor for the entire line
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     Dim temp() As IDynamicFormat = editControl1.GetLineBackColorFormats(editControl1.CurrentLine)
     Dim format As IBackgroundFormat = RegisterFormat()
     editControl1.SetLineBackColor(editControl1.CurrentLine, True, format)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
     For Each name As String In System.Enum.GetNames(GetType(HatchStyle))
          comboBox1.SelectedText = "Percent05"
          comboBox1.SelectedIndex = 0
          editControl1.Text += Constants.vbLf
          editControl1.CurrentLine = 1
     Next name
End Sub
'code to set the backcolor for a selected text
Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     Dim format As IBackgroundFormat = RegisterFormat()
End Sub


Reference link: https://help.syncfusion.com/windowsforms/syntaxeditor/text-visualization#customize-line-number-appearance

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile