Click here to Skip to main content
14,982,962 members
Articles / Desktop Programming / Windows Forms
Posted 8 Mar 2007


81 bookmarked


Rate me:
Please Sign up or sign in to vote.
4.93/5 (14 votes)
25 Mar 2007Apache2 min read
This article describes ColorTextBox, a customizable User Control which was written completely from scratch and is intended to fill the gap between the TextBox and RichTextBox controls found in the .NET 2.0 library.

Screenshot - colortextbox_pic.png


ColorTextBox is a .NET 2.0 User Control which was written from scratch and is meant as a replacement for the TextBox control of the .NET class library.


ColorTextBox is a by-product of LMX-Editor, an Open Source XML editor I developed as part of my diploma thesis. Since I was very disappointed by the performance of the RichTextBox control available in the .NET library (the standard TextBox does not support colored text), I decided to write my own ColorTextBox on which the aforementioned editor is based.

Using the code

Although ColorTextBox does not inherit from the abstract TextBoxBase class of the .NET library, it was designed to be compatible with the default TextBox implementation. So, if you're familiar with the usage of the standard TextBox, you can use ColorTextBox right away.

In fact, it should be no or little effort to replace TextBoxes in existing applications with instances of the ColorTextBox. If you develop under Visual Studio .NET 2005, you can use the Forms Designer to configure all relevant properties of the control.

Just look at the code provided in the example: it's a simple text editor which was built in about 30 minutes, and shows the most important features of the ColorTextBox.

Points of interest

As mentioned before, the ColorTextBox control is the base for an Open Source XML editor I wrote, which includes features like syntax highlighting and folding. If you want to write your own code editing component, have a look at the complete source code at SourceForge, which contains a generic CodeTextBox control which can be easily extended to support the mentioned features. Furthermore, the latest code for ColorTextBox will always be available under the link above!


03-08-07 Version 1.0.0:

  • Initial release
03-12-07 Version 1.0.1:
  • Added various keystroke shortcuts
  • Support for arbitrary input chars
03-25-07 Version 1.1.0:
  • Various bugfixes (Color support, Rendering, Scrolling, ...)
  • Added support for additional shortcut keys (similar to TextPad)
  • Added properties to improve compatability with the TextBox class
  • Added new demo application to demonstrate the most important features
  • Note: Some interfaces had to be changed!


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Austria Austria
No Biography provided

Comments and Discussions

Suggestionwhat if not multi-line? Pin
John Torjo8-Nov-15 19:56
professionalJohn Torjo8-Nov-15 19:56 
QuestionRead Only without cursor ? Pin
Wrangly6-Nov-13 2:51
MemberWrangly6-Nov-13 2:51 
QuestionWhy not TextBoxBase? Pin
i0013-Nov-11 17:12
Memberi0013-Nov-11 17:12 
GeneralMy vote of 5 Pin
Preky1-May-11 12:12
MemberPreky1-May-11 12:12 
Generalselect(int, int) Pin
Member 30574962-Jan-08 1:15
MemberMember 30574962-Jan-08 1:15 
General.SelectionBackColor property isn't in sync w/ rich text boxes Pin
cipher_nemo1-Nov-07 9:23
Membercipher_nemo1-Nov-07 9:23 
GeneralRe: .SelectionBackColor property isn't in sync w/ rich text boxes Pin
Chrisi4762-Nov-07 9:36
MemberChrisi4762-Nov-07 9:36 
QuestionNot working with KeyUp and KeyDown events? Pin
cipher_nemo28-Oct-07 10:28
Membercipher_nemo28-Oct-07 10:28 
AnswerRe: Not working with KeyUp and KeyDown events? Pin
cipher_nemo29-Oct-07 7:03
Membercipher_nemo29-Oct-07 7:03 
GeneralRe: Not working with KeyUp and KeyDown events? Pin
Chrisi4762-Nov-07 9:26
MemberChrisi4762-Nov-07 9:26 
GeneralFont anti-alias (ie: font smoothing, ClearType, etc.) Pin
cipher_nemo28-Oct-07 7:40
Membercipher_nemo28-Oct-07 7:40 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Chrisi4762-Nov-07 9:22
MemberChrisi4762-Nov-07 9:22 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
cipher_nemo12-Nov-07 4:31
Membercipher_nemo12-Nov-07 4:31 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Aki99911-Sep-08 1:53
MemberAki99911-Sep-08 1:53 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Cor Hoender18-Feb-09 22:42
MemberCor Hoender18-Feb-09 22:42 
Generalhi Pin
balakpn30-Apr-07 3:57
Memberbalakpn30-Apr-07 3:57 
GeneralRe: hi Pin
Chrisi4767-May-07 1:34
MemberChrisi4767-May-07 1:34 
GeneralRe: hi Pin
cipher_nemo28-Oct-07 7:04
Membercipher_nemo28-Oct-07 7:04 
GeneralFont Property doesn't work ... Pin
ODanny17-Apr-07 2:39
MemberODanny17-Apr-07 2:39 
GeneralRe: Font Property doesn't work ... Pin
Chrisi47617-Apr-07 21:05
MemberChrisi47617-Apr-07 21:05 
GeneralRe: Font Property doesn't work ... Pin
ODanny17-Apr-07 21:18
MemberODanny17-Apr-07 21:18 
QuestionPassword? Pin
nightrider131-Apr-07 11:27
Membernightrider131-Apr-07 11:27 
AnswerRe: Password? Pin
Chrisi4762-Apr-07 5:04
MemberChrisi4762-Apr-07 5:04 
GeneralRe: Password? Pin
nightrider133-Apr-07 0:48
Membernightrider133-Apr-07 0:48 
GeneralRich Text Pin
mo_kondori25-Mar-07 20:56
Membermo_kondori25-Mar-07 20:56 

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.