Click here to Skip to main content
Click here to Skip to main content

Background Highlighting with the RichTextBox the System way.

, 27 Apr 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
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

QuestionQ: How can I detect more than ONE name of font selected? Pinmembernanomartin29-Jan-07 17:35 
GeneralAppending text and keeping previous highlighting Pinmembermyalias1234567828-Nov-06 11:25 
GeneralDid you aware of "Highlight" stucks PinmemberSharon12316-May-06 1:09 
GeneralRe: Did you aware of "Highlight" stucks Pinmembersujit177923-Jul-09 20:33 
GeneralOutstanding Control PinmemberScott McCain8-May-06 22:46 
GeneralRe: Outstanding Control PinmemberScott McCain9-May-06 20:32 
GeneralWho can tell me ??? thanks you !!! Pinmemberhujinrong17-May-05 23:18 
GeneralVisual C++ 2005 express Pinmemberianw.moore28-Oct-04 22:06 
GeneralNice code, and easy to extend PinmemberRogerLainson26-Oct-04 21:39 
GeneralHighlighting with multiple forms PinmemberSajida Abdul Majeed11-Oct-04 21:20 
Generalcant use the dll in visual c# Pinmemberkenshi_178-Dec-03 18:47 
QuestionUpdates? Pinmemberlee_connell7-Jun-03 10:09 
GeneralNice Code... - a comment and a problem PinmemberZzzbla19-May-03 11:16 
GeneralRe: Nice Code... - a comment and a problem PinmemberLokiSD20-May-03 12:32 
GeneralRe: Nice Code... - a comment and a problem PinmemberZzzbla20-May-03 23:15 
GeneralPreProcessCmd PinmemberZzzbla21-May-03 3:41 
GeneralRe: PreProcessCmd PinmemberLokiSD21-May-03 4:02 
GeneralImprovements :) PinmemberJohn O'Byrne28-Apr-03 5:47 
GeneralRe: Improvements :) PinmemberLokiSD28-Apr-03 10:27 
GeneralRe: Improvements :) PinmemberJohn O'Byrne28-Apr-03 10:30 
GeneralRe: Improvements :) PinmemberGeminiMan29-Apr-03 10:18 
It is, but you can use Interop to make it happen. Since the RichTextBox is just interop anyhow it shouldn't matter one way or another.

On another one, being able to add Tables would be HIGHLY usefull...
GeneralRe: Improvements :) PinsussAnonymous4-Dec-03 9:45 
GeneralRe: Improvements :) Pinmemberspablos27-Sep-05 4:41 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 28 Apr 2003
Article Copyright 2003 by LokiSD
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid