Click here to Skip to main content
15,881,455 members
Articles / Desktop Programming / Windows Forms
Article

ColorTextBox

Rate me:
Please Sign up or sign in to vote.
4.93/5 (14 votes)
25 Mar 2007Apache2 min read 148.6K   3.4K   81   50
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

Introduction

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.

Background

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!

History

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!

License

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


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

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
Wrangly6-Nov-13 2:51 
QuestionWhy not TextBoxBase? Pin
i0013-Nov-11 17:12
i0013-Nov-11 17:12 
GeneralMy vote of 5 Pin
Preky1-May-11 12:12
Preky1-May-11 12:12 
Generalselect(int, int) Pin
Member 30574962-Jan-08 1:15
Member 30574962-Jan-08 1:15 
General.SelectionBackColor property isn't in sync w/ rich text boxes Pin
cipher_nemo1-Nov-07 9:23
cipher_nemo1-Nov-07 9:23 
GeneralRe: .SelectionBackColor property isn't in sync w/ rich text boxes Pin
Chrisi4762-Nov-07 9:36
Chrisi4762-Nov-07 9:36 
QuestionNot working with KeyUp and KeyDown events? Pin
cipher_nemo28-Oct-07 10:28
cipher_nemo28-Oct-07 10:28 
AnswerRe: Not working with KeyUp and KeyDown events? Pin
cipher_nemo29-Oct-07 7:03
cipher_nemo29-Oct-07 7:03 
As a work-around, I set my form's KeyPreview property to true, trapped KeyUp and KeyDown there, then had the form call the relevant methods for keyup and keydown of the ColorTextBox control. This isn't pretty, but it works.

_________________
Software Engineer
Penn State Facilities Engineering Institute

GeneralRe: Not working with KeyUp and KeyDown events? Pin
Chrisi4762-Nov-07 9:26
Chrisi4762-Nov-07 9:26 
GeneralFont anti-alias (ie: font smoothing, ClearType, etc.) Pin
cipher_nemo28-Oct-07 7:40
cipher_nemo28-Oct-07 7:40 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Chrisi4762-Nov-07 9:22
Chrisi4762-Nov-07 9:22 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
cipher_nemo12-Nov-07 4:31
cipher_nemo12-Nov-07 4:31 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Aki99911-Sep-08 1:53
Aki99911-Sep-08 1:53 
GeneralRe: Font anti-alias (ie: font smoothing, ClearType, etc.) Pin
Cor Hoender18-Feb-09 22:42
Cor Hoender18-Feb-09 22:42 
Generalhi Pin
balakpn30-Apr-07 3:57
balakpn30-Apr-07 3:57 
GeneralRe: hi Pin
Chrisi4767-May-07 1:34
Chrisi4767-May-07 1:34 
GeneralRe: hi Pin
cipher_nemo28-Oct-07 7:04
cipher_nemo28-Oct-07 7:04 
GeneralFont Property doesn't work ... Pin
ODanny17-Apr-07 2:39
ODanny17-Apr-07 2:39 
GeneralRe: Font Property doesn't work ... Pin
Chrisi47617-Apr-07 21:05
Chrisi47617-Apr-07 21:05 
GeneralRe: Font Property doesn't work ... Pin
ODanny17-Apr-07 21:18
ODanny17-Apr-07 21:18 
QuestionPassword? Pin
nightrider131-Apr-07 11:27
nightrider131-Apr-07 11:27 
AnswerRe: Password? Pin
Chrisi4762-Apr-07 5:04
Chrisi4762-Apr-07 5:04 
GeneralRe: Password? Pin
nightrider133-Apr-07 0:48
nightrider133-Apr-07 0:48 
GeneralRich Text Pin
mo_kondori25-Mar-07 20:56
mo_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.