Click here to Skip to main content
6,306,412 members and growing! (17,700 online)
Email Password   helpLost your password?
Desktop Development » Edit Controls » General     Beginner License: The Code Project Open License (CPOL)

Extended RichTextBox

By R. Syed

Rich Text Box control with built in options
VB (VB 7.x, VB 8.0, VB 9.0, VB 6), .NET (.NET 2.0), WinForms, Dev
Posted:8 Nov 2008
Views:8,149
Bookmarked:19 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
3 votes for this article.
Popularity: 1.30 Rating: 2.71 out of 5
1 vote, 33.3%
1

2

3

4
2 votes, 66.7%
5
RichTextBoxExDemo

Introduction

We all drop and use Rich Text Boxes control in our VB apps. It is a rich control (hence the name RichTextBox), with many options to format text. However, all options have to be used through coding in the background.

I have also worked with RTBs in several different applications, so I wrote this small extended control for the RichTextBox that displays a toolbar on top, with some common options that the user can perform. One cool option that I added is the spell check option (with help from another article on CodeProject, http://www.codeproject.com/KB/string/netspell.aspx)

So instead of dropping the RichTextBox in your form, drop the Extended RichTextBox :)

Background

I have seen several different posts for complete VB applications on the Internet that use RichTextBoxes to create WordPad type applications. They are very helpful for code reference, but you cannot just easily drop it in as a control and start using it. That is why I had to write this control.

Using the code

Basically if you just need to use the control on your form, you can simply add the dll as a reference, and be done with it. Download the demo project to see how that is setup. Make sure to include the en-US.dic file in your project. You can still use the control just as you would use a RichTextBox. The only difference is that it shows a nifty toolbox on top with options.

The actual control project is also included, so you can easily add other options and buttons if you need, or maybe even remove one if needed. All you have to do is handle the button click.

For example, this is how I handle toggling bullets:

Private Sub BulletsToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BulletsToolStripButton.Click

	rtb.SelectionBullet = Not rtb.SelectionBullet

	BulletsToolStripButton.Checked = rtb.SelectionBullet

End Sub
        

The first line performs the function, and the second line toggles the button for the function. Most functions implementations are just that simple.

Points of Interest

Note that if you select text that has formatting, it actually toggles the boxes. This is handled in the SelectionChanged event of the RichTextBox by simply setting the buttons checked value by comparing what the settings are at that position in the RichTextBox.

Possible Future Updates

I might post an update with options to hide/show each button, so that it makes it easy for the control user to control it better. Also, there are tons of features to add, like ComboBox font and font size selection, picture/object insert, save/open rtf files, etc.

License

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

About the Author

R. Syed


Member
I have been writing programs as a hobby since I was a teenager, and I have been working as a Professional Developer after graduating from University of Houston since 2002. Currently, I am one of the senior Developers at a Software Firm in Dallas, TX.

My area of expertise is developing management database systems for business so that they can efficiently store and lookup existing customer's information and related data, and be able to generate various reports. My goal is to always deliver innovative design and a user friendly interface.
Occupation: Software Developer (Senior)
Location: United States United States

Other popular Edit Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralHow to access the text property or equivalent PinmemberRiverKid10:17 4 Dec '08  
GeneralRe: How to access the text property or equivalent PinmemberRiverKid11:56 4 Dec '08  
GeneralIs there support for adding pictures ? PinmemberMasoud Dehghani10:03 10 Nov '08  
GeneralRe: Is there support for adding pictures ? PinmemberRazi Syed12:06 10 Nov '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 8 Nov 2008
Editor:
Copyright 2008 by R. Syed
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project