Click here to Skip to main content
Licence CPOL
First Posted 8 Sep 2008
Views 53,021
Downloads 1,480
Bookmarked 123 times

CodeTextBox - another RichTextBox control with syntax highlightning and intellisense

By Tamas Honfi | 8 Sep 2008
A RichTextBox control with syntax highlightning and intellisense.

1
1 vote, 3.3%
2
2 votes, 6.7%
3
4 votes, 13.3%
4
23 votes, 76.7%
5
4.88/5 - 30 votes
3 removed
μ 4.63, σa 1.36 [?]

Introduction

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...

Limitations:

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

Ideas:

  • 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.

References

History

  • 2008.09.08 - Version 1.0.

License

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

Member
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".

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSuggestions PinmemberMember 858171516:37 31 Jan '12  
AnswerSuper PinmemberMember 85241599:18 8 Jan '12  
Questiongood attempt Pinmemberleosco6:20 18 Nov '11  
GeneralNot adding the textbox to the toolbox Pinmember501st_commander13:08 17 Nov '10  
GeneralRe: Not adding the textbox to the toolbox PinmemberMember 858171516:38 31 Jan '12  
GeneralMy vote of 5 PinmemberAmir Mehrabi-Jorshary23:16 1 Nov '10  
GeneralGood work, some critique PinmemberBigdeak1:12 10 Jun '10  
GeneralGreat job. Pinmemberetsimber4:15 2 Jun '10  
GeneralConverting to silvellight PinmemberAndrusM5:53 19 Apr '10  
GeneralWell Done! PinmemberChristo6675:35 19 Apr '10  
GeneralHelp [modified] Pinmemberleosco5:05 17 Dec '09  
Generalnot efficient Pinmemberhsj52805:13 2 Feb '09  
GeneralRe: not efficient PinmemberChristo6675:39 19 Apr '10  
GeneralRemove pinove call to run under moni, imporve speed PinmemberAndrusM6:24 20 Oct '08  
GeneralRe: Remove pinove call to run under moni, imporve speed PinmemberThe_Mega_ZZTer17:05 23 Jun '09  
GeneralRe: Remove pinove call to run under moni, imporve speed PinmemberChristo6675:46 19 Apr '10  
GeneralCannot open with Visual Studio 2005 express Pinmemberg.bude2:02 17 Sep '08  
GeneralOr Visual Studio 2005 Pro Pinmembereddiem918:10 14 Oct '08  
GeneralRe: Or Visual Studio 2005 Pro PinmemberTamas Honfi23:52 14 Oct '08  
GeneralFlashing on paste PinmemberAndrusM7:17 16 Sep '08  
GeneralRe: Flashing on paste PinmemberTamas Honfi1:32 17 Sep '08  
GeneralRe: Flashing on paste PinmemberAndrusM2:04 17 Sep '08  
GeneralRe: Flashing on paste PinmemberTamas Honfi2:20 17 Sep '08  
Hi Andrus,
 
as I see, this class uses a space-separated list of strings for the words to highlight.
Splitting that strings for space, and addig the result arrays to the proper List collections of CodeTextbox should work.
Unfortunately, this version doesn't support string highlightning, but u can highlight preprocessors with the function list, and u can gain an additional color. Smile | :)
 
The buffer-richTextbox solution is interesting, but I don't have any idea, how slow it could be because of the duplicate pastes, especially for larger texts...
 

Regards,
 
Tamas

GeneralOther solutions PinmemberRednaxelaFX2:23 8 Sep '08  
GeneralRe: Other solutions Pinmemberdave.dolan10:14 8 Sep '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120210.1 | Last Updated 8 Sep 2008
Article Copyright 2008 by Tamas Honfi
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid