Click here to Skip to main content
12,396,961 members (42,054 online)
Click here to Skip to main content
Add your own
alternative version

Stats

157.9K views
2.8K downloads
56 bookmarked
Posted

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

Introduction

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.

License

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

Share

About the Author

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

You may also be interested in...

Comments and Discussions

 
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 
Hi, this looks good, but you should add a feature to your derived class:

InsertImage(Image img);

I found code to do this on google:

public void InserImage()
  {
   System.Windows.Forms.OpenFileDialog fileDialog = new OpenFileDialog();
   fileDialog.Filter = "JPEG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|PNG
(*.png)|*.png";//|html Document (*.html)|*.htm*|All files(*.*)|*.*";
   fileDialog.RestoreDirectory =true;
   if(fileDialog.ShowDialog() == DialogResult.Cancel )
    return;
   string lstrFile = fileDialog.FileName;
   Bitmap myBitmap = new Bitmap(lstrFile);
   // Copy the bitmap to the clipboard.
   Clipboard.SetDataObject(myBitmap);
   // Get the format for the object type.
   DataFormats.Format myFormat = DataFormats.GetFormat
    (DataFormats.Bitmap);
   // After verifying that the data can be pasted, paste
   if(NoteBox.CanPaste(myFormat))
   {
    NoteBox.Paste(myFormat);
   }
   else
   {
    MessageBox.Show("The data format that you attempted ste is not supported
by this control.");
   } NoteBox.Focus();
  }

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

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