C# – Custom code editor

Did you ever need a code editor embedded in your program? When I am running around some forums and read articles about interesting library, I discovered a very useful library which allows me to have a code editor directly in my program. This code editor control is ScintillaNET and parses our code very beautifully as image below

The homepage of this .net control is http://scintillanet.codeplex.com/ . Just navigate to that website, download and add reference to it from project. You need to read the instructions for installing carefully otherwise the control can not be compiled. For example, if you meet the error “%1 is not a valid Win32 application” as in my case, you can read instructions here to fix it http://scintillanet.codeplex.com/WorkItem/View.aspx?WorkItemId=23101 . I just copy ScintillaNET DLL to folder of program, set to run only on 0x86 operating system and everything runs smoothly. We can adjust some settings so that we have a professional code editor. For example,

1. Enable syntax highlighting through define the language of source code

Syntax highlighting

2. Enable code line number

3. Enable folds to group and un-group block of code

For more advanced features you can read homepage of control. I built a running example which you can download here. “Custom code editor

There are of course some alternatives to ScintillaNET which I list below
– Actipro SyntaxEditor http://www.actiprosoftware.com/products/DotNet/WindowsForms/SyntaxEditor/Default.aspx
– AqiStar.TextBox http://www.aqistar.com/
– AvalonEdit http://wiki.sharpdevelop.net/%28X%281%29S%28sbe5bd45peye2m45jr4wka55%29%29/AvalonEdit.ashx