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 create a VS.NET like code insertion application using WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl

Insertion feature

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:







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.

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