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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I create a VS.NET like code insertion application using EditControl ?

 

Since there is no direct way of accessing the DOM object associated with the file contained in the EditControl, it cannot identify the classes and its APIs contained in the file dynamically. The names of the classes and its APIs (at least regular expressions specifying them) have to be specified in the configuration file used the EditControl. This configuration file is then plugged into the EditControl and used for syntax highlighting its contents.

Please refer to the test sample attached below. In this sample, the following format and lexem definitions have been specified to identify the method, property and event handler names.

<format name="EventHandler" Font="Courier New, 10pt, style=Bold" FontColor="Orange" />

<format name="MethodName" Font="Courier New, 10pt, style=Bold" FontColor="Red" />

<format name="PropertyName" Font="Courier New, 10pt, style=Bold" FontColor="Khaki" />

<lexem BeginBlock="CustomEventHandler[0-9]*" IsBeginRegex="true" Type="EventHandler"/>

<lexem BeginBlock="Method[0-9]*" IsBeginRegex="true" Type="MethodName"/>

<lexem BeginBlock="Property[0-9]*" IsBeginRegex="true" Type="PropertyName"/>

A sample file - test.cs containing a simple class TestClass has been loaded into the EditControl. Presently this sample contains the auto-code insertion feature for the event handlers only. This can be easily extended for the methods and properties as well. We have used an external configuration file – CustomConfig.xml which is an extended version of the config file used to highlight C#. I have plugged this into the EditControl using the following code :

C#

this.editControl1.Configurator.Open(configFilePath);

this.editControl1.ApplyConfiguration("CustomLanguage");

VB

Me.editControl1.Configurator.Open(configFilePath)

Me.editControl1.ApplyConfiguration("CustomLanguage")

Please follow the steps below to test this sample.

1. Run the sample.

2. From the combobox, select any of the event handlers – for example : CustomEventHandler3. Note that the EditControl scrolls the appropriate line into view and inserts some custom code.

3. Now type some event handler name into the combobox – for example : CustomEventHandler4. Note that the EditControl correctly inserts an event handler block with the specified name.

The only limitation here is that the names of the event handlers should match the regular expression specified – CustomEventHandler[0-9]*. You could support names of any format by specifying an appropriate regular expression.

Article ID: Published Date: Last Revised Date: Platform: Control:
363 04/30/2011 07/10/2014 WinForms 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