Click here to Skip to main content
15,392,679 members
Articles / Programming Languages / C#
Posted 8 Sep 2008


148 bookmarked

CodeTextBox - another RichTextBox control with syntax highlightning and intellisense

Rate me:
Please Sign up or sign in to vote.
4.87/5 (34 votes)
8 Sep 2008CPOL2 min read
A RichTextBox control with syntax highlightning and intellisense.

Image 1


I needed a script-editor control for one of my projects, with syntax highlighting and intellisense for more comfort. I did a search on CodeProject and Google, but didn't find any - just separate solutions for one of the two functions... The one I found with both syntax highlighting and intellisense just wasn't flexible enough for me, because it could be used only for C#, and only could handle classes (intellisense popped up after pressing the . key). As I wanted to use this mostly for LUA, this simply wasn't enough. I decided to use this control as a sample, and write my own, flexible one... After a few days, I came out with this: I have a flexible syntax-highlighter, with intellisense. :) I can edit everything in design mode, for example, the intellisense hotkey, or the scope-operator's list... Yes, I can handle not just the point, but more like ::, or ->, with C++ language support in mind. :)

Using the code

I designed the CodeTextBox control to be easy to work with: you can edit all the necessary properties in design mode as well, under the CodeTextBox category.

CodeTextBox properties

There're some things that I couldn't do automatically, or put in Design mode...

  • If you put text in the CodeTextBox programmatically, you should update syntax highlighting to get the proper results.
  • You can do it like this: codeTextBox1.UpdateSyntaxHightlight();.

  • I used the built-in TreeView control to store intellisense's data. I know it's a waste of resources, but it was a fast solution for now, and I need to give some instructions on how to use it, because there's a lot of things there...
  • To build up the intellisense-tree, you should add items to the intellisense-tree's nodes. I use the node's Name and Tag attributes for intellisense. Name should contain the name of the intellisense item, Tag should contain one of the following: class, event, interface, namespace, method, or property. Intellisense will assign images before the names based on this Tag property.

Limitations, Ideas

I know that it's not perfect yet, but hey, it's useable... :) Let me tell you some ideas to make this better, and also some of its limitations that I haven't been able to solve until now...


As in most syntax highlighters, I cannot handle C-style comment blocks, and keywords like #region.


  • Implementing an XML serializer for the syntax highlighter and the intellisense to enable ease-of-use, and for a more comfortable language support.
  • Implementing some .NET-Reflection support for the intellisense to let it handle .NET based scripting easier.
  • Replacing the TreeView with a tinier container, but keeping the easy design-time edit function that TreeView has.



  • 2008.09.08 - Version 1.0.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tamas Honfi
Software Developer (Senior) Moonlight Studios
Hungary Hungary
I'm working as a software developer since 2005 mostly using C# and MS SQL Server for building windows and web applications. I have 3 years experience in developing CRM softwares, but I'm also interested in Game development using C++, DirectX, and C#-XNA.
I'm always open for new technologies, preferring code reusability, stability, and "nice solutions".

Comments and Discussions

QuestionWow, does not work Pin
Nobbicheck17-Aug-17 20:09
MemberNobbicheck17-Aug-17 20:09 
AnswerRe: Wow, does not work Pin
Member 373058722-Oct-17 8:31
MemberMember 373058722-Oct-17 8:31 
Question[My vote of 1] This project should be deleted. There is no tutorial on how it works, and resources do not work with 2010-2015 Pin
aaava16-Feb-16 17:04
Memberaaava16-Feb-16 17:04 
AnswerRe: [My vote of 1] This project should be deleted. There is no tutorial on how it works, and resources do not work with 2010-2015 Pin
Member 373058722-Oct-17 8:29
MemberMember 373058722-Oct-17 8:29 
QuestionDoen't work! Error: Resource not available! Pin
C4RL.026-Sep-13 22:59
MemberC4RL.026-Sep-13 22:59 
AnswerRe: Doen't work! Error: Resource not available! Pin
Wrangly15-Oct-13 2:01
MemberWrangly15-Oct-13 2:01 
AnswerRe: Doen't work! Error: Resource not available! Pin
Member 93225358-Dec-13 13:43
MemberMember 93225358-Dec-13 13:43 
Questionhow I can use intellisense separately Pin
luislasonbra6-Apr-13 9:18
Memberluislasonbra6-Apr-13 9:18 
GeneralMy vote of 5 Pin
Greg_han21-Jan-13 18:07
MemberGreg_han21-Jan-13 18:07 
GeneralVery Good Work Pin
Dnyaneshwar Kotwal19-Aug-12 20:00
professionalDnyaneshwar Kotwal19-Aug-12 20:00 
QuestionSuggestions Pin
Member 858171531-Jan-12 15:37
MemberMember 858171531-Jan-12 15:37 
AnswerSuper Pin
Member 85241598-Jan-12 8:18
MemberMember 85241598-Jan-12 8:18 
Questiongood attempt Pin
Rayan Isran18-Nov-11 5:20
MemberRayan Isran18-Nov-11 5:20 
GeneralNot adding the textbox to the toolbox Pin
501st_commander17-Nov-10 12:08
Member501st_commander17-Nov-10 12:08 
GeneralRe: Not adding the textbox to the toolbox Pin
Member 858171531-Jan-12 15:38
MemberMember 858171531-Jan-12 15:38 
GeneralMy vote of 5 Pin
Amir Mehrabi-Jorshari1-Nov-10 22:16
MemberAmir Mehrabi-Jorshari1-Nov-10 22:16 
GeneralGood work, some critique Pin
Bigdeak10-Jun-10 0:12
MemberBigdeak10-Jun-10 0:12 
GeneralGreat job. Pin
etsimber2-Jun-10 3:15
Memberetsimber2-Jun-10 3:15 
GeneralConverting to silvellight Pin
AndrusM19-Apr-10 4:53
MemberAndrusM19-Apr-10 4:53 
GeneralWell Done! Pin
Christo66719-Apr-10 4:35
MemberChristo66719-Apr-10 4:35 
GeneralHelp [modified] Pin
Rayan Isran17-Dec-09 4:05
MemberRayan Isran17-Dec-09 4:05 
Generalnot efficient Pin
hsj52802-Feb-09 4:13
Memberhsj52802-Feb-09 4:13 
GeneralRe: not efficient Pin
Christo66719-Apr-10 4:39
MemberChristo66719-Apr-10 4:39 
GeneralRemove pinove call to run under moni, imporve speed Pin
AndrusM20-Oct-08 5:24
MemberAndrusM20-Oct-08 5:24 
GeneralRe: Remove pinove call to run under moni, imporve speed Pin
The_Mega_ZZTer23-Jun-09 16:05
MemberThe_Mega_ZZTer23-Jun-09 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.