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


, 21 Jun 2006
Rate this:
Please Sign up or sign in to vote.
A RichTextBox with a richtext toolbar.

RichTextBoxExtended ScreenShot


Hello again, my friends. Today's control is a very simple yet useful control. It is a custom control that contains both a RichTextBox and a Toolbar. Now you might ask: "Why is that so important and useful?" It's because I have taken the liberty to do some coding for you. The toolbar not only looks pretty but it's functional too. It contains some of the everyday, plain, and simple things you want your users to be able to do when they input text.


[Cheesy flashback music and graphics.] It all started when I was trying to remember how to insert a rich text "stamp" into a RichTextBox. Along the road to remembering, I thought to myself "Self, wouldn't it be easier not to have to remember this stuff every 6 months?" My answer was a big yes. It would be easier if I just built a control to use every time I needed users to input text. Then thinking of all the wonderful and helpful people on The Code Project, I decided to distribute my control so that everyone can learn how to do this stuff and also so they will have a pre-built control for use whenever they want.

Using the control

There are two ways you can use this control. You can either add the RichTextBoxExtended.cs file to your project and use the control by setting it up in code, or you can add the control to your toolbar and drag it on to your Form. One other thing, if you add the .cs file to your project, you will also have to add an ImageList to your project that contains all the images for the Toolbar. I prefer (and suggest) the latter method because I get to see the control on the form and I don't have to create the ImageList on every form I want to use this control on.

There are several properties that will help you use this control, and they are listed below:

  • AcceptsTab
  • AutoWordSelection
  • ReadOnly
  • ShowBold
  • ShowCenterJustify
  • ShowColors
  • ShowCopy
  • ShowCut
  • ShowFont
  • ShowFontSize
  • ShowItalic
  • ShowLeftJustify
  • ShowOpen
  • ShowPaste
  • ShowRedo
  • ShowRightJustify
  • ShowSave
  • ShowStamp
  • ShowStrikeout
  • ShowUnderline
  • ShowUndo
  • StampColor
  • StampAction
  • Toolbar - only use at runtime, changes that are made at design time will not persist.
  • RichTextBox - only use at runtime, changes that are made at design time will not persist.

Out of all of these, most of them are simply turning features on and off. The only really special ones are StampColor, StampAction, Toolbar, and RichTextBox.

  • StampColor is what it sounds like. It is the color the text will be in when a stamp is added to the RichTextBox.
  • StampAction can be one of three values: EditedBy, DateTime, or Custom.
  • EditBy is a string that reads "Edited by " + CurrentPrincipal.Identity.Name + " (theUserName) on " + DateTime.Now.ToLongDateString().
  • DateTime: DateTime.Now.ToLongDateString().
  • Custom: For Custom, you must handle the stamp event of this control.
private void richTextBoxExtended1_Stamp(object sender, System.EventArgs e)
    //holds our stamp text
    StringBuilder stamp = new StringBuilder("");
    if(richTextBoxExtended1.RichTextBox.Text.Length > 0)
      stamp.Append("\r\n\r\n"); //add two lines for space
    stamp.Append("Custom stamp goes here!\r\n");

    //unselect everything basicly
    richTextBoxExtended1.RichTextBox.SelectionLength = 0;
    richTextBoxExtended1.RichTextBox.SelectionStart =
       //start new selection at the end of the text

      = richTextBoxExtended1.StampColor;
      //make the selection blue
    richTextBoxExtended1.RichTextBox.SelectionFont =
      new Font(richTextBoxExtended1.RichTextBox.SelectionFont,
      FontStyle.Bold); //set the selection font and style
    //add the stamp to the richtextbox

    //set focus back on the richtextbox

Points of Interest

The biggest point of interest after all these months now is the amount of feedback, interest, and work one little control can bring to your life. I haven't been able to maintain this code like I wanted but thanks to all that have helped and made suggestions along the way. Along with this updated article comes news of RichTextBoxExtended for Framework 2.0. So if you want all these features in VS 2005 then keep watching. Anyone wanting to help, just email me.

OK, so what did I learn from this control and this experience? I learned about Exclusive-OR. This is a really handy operation that saved me 100 or so lines of code in this control. In the code below, the OR is the "^". The best way I can explain it is, it takes two values like 00000001 and 00000010 and compares them. In the example below, it checks the style and if the style = 00000001, it will change it to 00000000, however if it is 00000000, then it will change it to 00000001. That isn't the best explanation of this operation, so below the code are some links for you.

rtb1.SelectionFont = new Font(rtb1.SelectionFont,
              rtb1.SelectionFont.Style ^ FontStyle.Bold);


  • 1.0 - Initial release - 1/31/2004.
  • 1.1 - 4/18/2005.
    • Font Selector added.
    • Font Size Selector added.
    • Fixed error that caused the control to crash when two or more font types were selected.
    • Cleaned up the code.
  • 1.2 - 12/12/2005
    • Fixed multiple font selection bug. You can now add font styles (e.g. Bold and Color) when selecting two different fonts at the same time.
    • Added a selection change event named SelChanged.
    • Added cut, copy and paste buttons.
    • The control now uses the ToolBarButton.Tag property instead of the ToolBarButton.ToolTip property for button presses. Now you can have your tooltips be whatever you like.
    • Added DetectUrls property. You can have HTTP links in your RichTextBox and click them to open the system default browser.
    • Added a ReadOnly property.
    • Added AcceptsTabs property.
    • Added AutoWordSelection property.
    • Added keyboard handler for Ctrl+B, Ctrl+I, Ctrl+S, Ctrl+U, Ctrl+-.
    • The download now comes with all the images. I also included a print image.
    • Cleaned up the code.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Richard Parsons
Web Developer
United States United States
Richard is a contract developer that currently lives in Arkansas. He has spent most of his career working in healthcare related companies. On his first job he was programming asp using VBScript and his boss walked in and told the whole group to get in their cars and drive to Barnes and Nobles. Once there he let everyone buy a few books about .NET and then he dropped the bomb, he said we would no longer write asp code. Starting Monday we were to be .NET developers.

Five years later Richard is a competent and self motivated .NET developer that can tackle most any problem. He has recently started his own business BellaDev which is proving to be a fun and challenging opportunity.

Comments and Discussions

QuestionGood! PinmemberMarco Bahamondes28-Aug-14 6:57 
QuestionAdd Table Pinmemberloserkidz3214-Nov-13 0:27 
QuestionLicense PinmemberMember 1033556915-Oct-13 3:33 
QuestionSo powerfull control, but I have small problem with it Pinmemberyasser hosny20-Dec-12 2:42 
Questioncould i use it for some project to make money Pinmemberxuping1111029-Nov-12 23:37 
GeneralMy vote of 1 PinmemberIgor9515-Nov-12 18:27 
GeneralMy vote of 5 Pinmemberpcs041425-Oct-12 5:11 
QuestionI don't know why I can't use f.RichTextBoxEx1.rtb.rtf PinmemberCup of Coffee25-Apr-12 12:44 
AnswerRe: I don't know why I can't use f.RichTextBoxEx1.rtb.rtf PinmemberStijn Courtheyn9-Dec-12 3:49 
GeneralThanks Pinmembersi2480319-Oct-10 7:02 
QuestionHow to retrieve richtext from MySql and display on form PinmemberElikhater14-Apr-10 21:26 
GeneralGreat control Pinmemberschuetzem7812-Apr-10 11:15 
GeneralThanks alot! PinmemberDelfy_Coltech28-Oct-09 16:33 
GeneralUsing GDI+ to print RTF texts Pinmemberromias24-Sep-09 8:33 
Questionhow to use whit a databse Pinmemberfaramendi26-Aug-09 6:49 
AnswerRe: how to use whit a databse Pinmemberromias24-Sep-09 8:26 
Questionhow to use whit a databse Pinmemberfaramendi26-Aug-09 6:48 
QuestionLicense? PinmemberPhilDeets3-Aug-09 11:27 
GeneralTool tip text PinmemberMember 269378016-Feb-09 23:10 
GeneralRe: Tool tip text PinmemberMember 269378016-Feb-09 23:15 
GeneralMinor improvements Pinmembermb1826-Sep-08 6:35 
GeneralBug in paste operation with .Net 2.0 Pinmemberchk_at9-Apr-08 1:05 
GeneralSetting margins based on RTF Margin Size Pinmembermgladding13-Nov-07 11:36 
GeneralRe: Setting margins based on RTF Margin Size PinmemberSKiLLa26-Mar-08 6:55 
QuestionI want to send RichTextData via E-mail Pinmemberm_salman27-Sep-07 0:25 
AnswerRe: I want to send RichTextData via E-mail PinmemberRichard Parsons27-Sep-07 5:12 
AnswerRe: I want to send RichTextData via E-mail Pinmemberm_salman29-Sep-07 1:45 
GeneralThanx! PinmemberS. Vasiliev26-Jul-07 3:49 
QuestionCan I use this? PinmemberRunnerDude6-Jul-07 8:49 
AnswerRe: Can I use this? PinmemberRichard Parsons12-Jul-07 17:31 
Questiondoes not contain a static 'Main' method Pinmemberjoziiik1-Mar-07 4:11 
AnswerRe: does not contain a static 'Main' method PinmemberRichard Parsons1-Mar-07 4:18 
GeneralRe: does not contain a static 'Main' method Pinmemberjoziiik1-Mar-07 5:02 
GeneralRe: does not contain a static 'Main' method Pinmemberjoziiik1-Mar-07 5:03 
GeneralRe: does not contain a static 'Main' method Pinmemberjoziiik1-Mar-07 5:09 
GeneralRe: does not contain a static 'Main' method PinmemberRichard Parsons1-Mar-07 5:22 
GeneralRe: does not contain a static 'Main' method Pinmemberjoziiik1-Mar-07 5:48 
GeneralRe: does not contain a static 'Main' method Pinmemberenphit15-Apr-10 22:21 
QuestionTab-Stops in RichTextBoxExtended PinmemberSalgerion7-Feb-07 4:55 
AnswerRe: Tab-Stops in RichTextBoxExtended PinmemberRichard Parsons8-Feb-07 4:26 
AnswerRe: Tab-Stops in RichTextBoxExtended PinmemberRichard Parsons8-Feb-07 4:50 
GeneralRe: Tab-Stops in RichTextBoxExtended PinmemberSalgerion9-Feb-07 3:47 
AnswerRe: Tab-Stops in RichTextBoxExtended PinmemberRichard Parsons9-Feb-07 4:40 
GeneralRe: Tab-Stops in RichTextBoxExtended PinmemberScott S.31-Oct-07 7:39 
GeneralDesktop Notes & Contacts uses this control PinmemberJeremy Beckham31-Jan-07 4:11 
GeneralRe: Desktop Notes & Contacts uses this control PinmemberRichard Parsons31-Jan-07 4:30 
QuestionAdded functionality? PinmemberGimlei30-Jan-07 16:42 
QuestionBullets ? PinmemberEdward1118-Jan-07 13:00 
Generaltoolbar repaint problem Pinmembermerkuriev_sergey28-Dec-06 1:39 
GeneralIntellectual Property Rights PinmemberFlying Jett7-Dec-06 14:02 

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
Web03 | 2.8.150331.1 | Last Updated 21 Jun 2006
Article Copyright 2005 by Richard Parsons
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid