Click here to Skip to main content
5,787,682 members and growing! (19,498 online)
Email Password   helpLost your password?
Desktop Development » Edit Controls » General     Beginner License: The Code Project Open License (CPOL)

Extended RichTextBox

By Razi Syed

Rich Text Box control with built in options
VB (VB 7.x, VB 8.0, VB 9.0, VB 6, VB), .NET (.NET, .NET 2.0), WinForms, Dev

Posted: 8 Nov 2008
Updated: 8 Nov 2008
Views: 3,527
Bookmarked: 18 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
3 votes for this Article.
Popularity: 1.30 Rating: 2.71 out of 5
1 vote, 33.3%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
2 votes, 66.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article
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

Razi Syed



Occupation: Software Developer (Senior)
Location: United States United States

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralHow to access the text property or equivalentmemberRiverKid10:17 4 Dec '08  
GeneralRe: How to access the text property or equivalentmemberRiverKid11:56 4 Dec '08  
GeneralIs there support for adding pictures ?memberMasoud Dehghani10:03 10 Nov '08  
GeneralRe: Is there support for adding pictures ?memberRazi 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 Razi Syed
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project