)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to perform the language based Syntax highlighting in WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl |
Published Date: April 30, 2011 |
Last Revised Date: December 13, 2019

Syntax highlighting

The SyntaxEditor (EditControl) supports Syntax highlighting for C#, VB, XML, HTML, Pascal and Delphi.

Please refer to the code snippets below code for how to customize the configuration settings at run-time.

C#

private void menuItem1_Click(object sender, System.EventArgs e)
{
    try
    {
        IConfigLanguage activeLang = this.editControl1.Parser.Formats as IConfigLanguage;
        frmConfigDialog editConfig = new frmConfigDialog(this.editControl1.Configurator,activeLang);
        if(editConfig.ShowDialog(this) == DialogResult.OK && activeLang != null)
        {
            IConfigLanguage newLang = editConfig.Configurator.KnownLanguageNames.Contains(activeLang.Language)?
editConfig.Configurator[ activeLang.Language ] : editConfig.Configurator.DefaultLanguage;
            if( newLang != null )
            {
               this.editControl1.Configurator = editConfig.Configurator;
               this.editControl1.ResetColoring( newLang );
            }
        }
    }
    catch( ArgumentException ex )
    {
        Debug.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace );
        throw;
    }
}
private void menuItemCSharp_Click(object sender, System.EventArgs e)
{
    this.editControl1.LoadFile("..\\..\\Test Files\\CSharpSource.cs");
}
private void menuItemVB_Click(object sender, System.EventArgs e)
{
    this.editControl1.LoadFile("..\\..\\Test Files\\VBSource.vb");
}

 

VB

Private Sub menuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menuItem1.Click
    Try
         Dim activeLang As IConfigLanguage = Me.editControl1.Parser.Formats '
         Dim editConfig As New frmConfigDialog(Me.editControl1.Configurator, activeLang)
         If editConfig.ShowDialog(Me) = DialogResult.OK AndAlso Not (activeLang Is Nothing) Then
            Dim newLang As IConfigLanguage = IIf(editConfig.Configurator.KnownLanguageNames.Contains(activeLang.Language),
editConfig.Configurator(activeLang.Language), editConfig.Configurator.DefaultLanguage) 'TODO: For performance
reasons this should be changed to nested IF statements
            If Not (newLang Is Nothing) Then
               Me.editControl1.Configurator = editConfig.Configurator
               Me.editControl1.ResetColoring(newLang)
            End If
         End If
         Catch ex As ArgumentException
              Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace)
         Throw
     End Try
End Sub
Private Sub menuItemCsharp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
menuItemCsharp.Click
     Me.editControl1.LoadFile("..\Test Files\CSharpSource.cs")
End Sub
Private Sub MenuItemVB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemVB.Click
     Me.editControl1.LoadFile("..\Test Files\VBSource.vb")
End Sub

 

Reference link: https://help.syncfusion.com/windowsforms/syntaxeditor/syntax-highlighting

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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
Live Chat Icon