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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I perform the language based Syntax highlighting in EditControl?

 

This sample demonstrates the language based Syntax highlighting feature in EditControl.

EditControl supports Syntax highlighting for C#, VB, XML, HTML, Pascal and Delphi.

Please refer to the code snippets below and the sample attached to know how to customize the configuration settings at run-time.

C#

Code to invoke Configuration dialog for customizing configuration settings at run-time

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");

}

C#

Code to invoke Configuration dialog for customizing configuration settings at run-time

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

Article ID: Published Date: Last Revised Date: Platform: Control:
318 04/30/2011 07/10/2014 Windows Forms EditControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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