Click here to Skip to main content
14,635,719 members
Articles » Languages » C / C++ Language » General
Posted 27 Apr 2003


58 bookmarked

Background Highlighting with the RichTextBox the System way.

Rate this:
4.91 (19 votes)
Please Sign up or sign in to vote.
4.91 (19 votes)
27 Apr 2003CPOL
Adds support for setting the background color in the RichTextBox more directly than volking's article.

Sample Image - tarrorichtextbox.png


This DLL extends the RichTextBox control in Windows Forms to add background highlighting color, background color clearing, highlighting and 'Scroll To Bottom' support. The article on CodeProject by Frederick Volking entitled "RichTextBox with background highlighting in VB.NET" does pretty much the same as this, only his article edits the color tables and RTF text currently used in the RichTextBox. My version uses calls on the RichTextBox directly to highlight/clear selections.

Functionality Added

A stonking 4 (count them) methods are added to the RichTextBox:

  • RichTextBox.SelectionBackColor (Property) - Gets or sets the current selection's backcolor. Used the same way as RichTextBox.SelectionColor.
  • RichTextBox.ClearBackColor (Sub) - Clears all or just the selected backcolor as though it was never there.
  • RichTextBox.Highlight (Sub) - Highlights the given text in the RichTextBox with the given color.
  • RichTextBox.ScrollToBottom (Sub) - Scrolls the RichTextBox to the bottom of the viewport.

Reusing the New RichTextBox

The release version of the dll is included in the demo project, simply reference this DLL and add the DLL to the toolbox, then drop the new RichTextBox onto a form, then you are all done.


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


About the Author

Web Developer
United Kingdom United Kingdom
Self taught programmer of 6 years or so, started on the ZX Spectrum, through to the Amiga and then the PC. Enjoy coding for fun, most of my work is done in VB.NET, although have a background in many other langauges. Enjoy fiddling with Win32 and writing the odd small game here and there.

Currently studying a BSc(Hons) Software Engineering course at University.

Comments and Discussions

QuestionThanks! Pin
Akacoo11-Mar-20 9:09
MemberAkacoo11-Mar-20 9:09 
QuestionQ: How can I detect more than ONE name of font selected? Pin
nanomartin29-Jan-07 16:35
Membernanomartin29-Jan-07 16:35 
GeneralAppending text and keeping previous highlighting Pin
myalias1234567828-Nov-06 10:25
Membermyalias1234567828-Nov-06 10:25 
GeneralDid you aware of "Highlight" stucks Pin
Sharon12316-May-06 0:09
MemberSharon12316-May-06 0:09 
GeneralRe: Did you aware of "Highlight" stucks Pin
sujit177923-Jul-09 19:33
Membersujit177923-Jul-09 19:33 
GeneralOutstanding Control Pin
Scott McCain8-May-06 21:46
MemberScott McCain8-May-06 21:46 
GeneralRe: Outstanding Control Pin
Scott McCain9-May-06 19:32
MemberScott McCain9-May-06 19:32 
GeneralWho can tell me ??? thanks you !!! Pin
hujinrong17-May-05 22:18
Memberhujinrong17-May-05 22:18 
GeneralVisual C++ 2005 express Pin
ianw.moore28-Oct-04 21:06
Memberianw.moore28-Oct-04 21:06 
GeneralNice code, and easy to extend Pin
RogerLainson26-Oct-04 20:39
MemberRogerLainson26-Oct-04 20:39 
GeneralHighlighting with multiple forms Pin
Sajida Abdul Majeed11-Oct-04 20:20
MemberSajida Abdul Majeed11-Oct-04 20:20 
Generalcant use the dll in visual c# Pin
kenshi_178-Dec-03 17:47
Memberkenshi_178-Dec-03 17:47 
QuestionUpdates? Pin
lee_connell7-Jun-03 9:09
Memberlee_connell7-Jun-03 9:09 
GeneralNice Code... - a comment and a problem Pin
Zzzbla19-May-03 10:16
MemberZzzbla19-May-03 10:16 
GeneralRe: Nice Code... - a comment and a problem Pin
LokiSD20-May-03 11:32
MemberLokiSD20-May-03 11:32 
GeneralRe: Nice Code... - a comment and a problem Pin
Zzzbla20-May-03 22:15
MemberZzzbla20-May-03 22:15 
GeneralPreProcessCmd Pin
Zzzbla21-May-03 2:41
MemberZzzbla21-May-03 2:41 
GeneralRe: PreProcessCmd Pin
LokiSD21-May-03 3:02
MemberLokiSD21-May-03 3:02 
GeneralImprovements :) Pin
John O'Byrne28-Apr-03 4:47
MemberJohn O'Byrne28-Apr-03 4:47 
GeneralRe: Improvements :) Pin
LokiSD28-Apr-03 9:27
MemberLokiSD28-Apr-03 9:27 
GeneralRe: Improvements :) Pin
John O'Byrne28-Apr-03 9:30
MemberJohn O'Byrne28-Apr-03 9:30 
GeneralRe: Improvements :) Pin
GeminiMan29-Apr-03 9:18
MemberGeminiMan29-Apr-03 9:18 
GeneralRe: Improvements :) Pin
Anonymous4-Dec-03 8:45
MemberAnonymous4-Dec-03 8:45 
GeneralRe: Improvements :) Pin
spablos27-Sep-05 3:41
Memberspablos27-Sep-05 3:41 

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.