How do I perform the language based Syntax highlighting in EditControl?
(Views :1209)

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
::adCenter::