Click here to Skip to main content
13,260,383 members (44,709 online)
Click here to Skip to main content
Add your own
alternative version


157 bookmarked
Posted 8 Jan 2008

Advanced Text Editor with Ruler

, 20 Mar 2008
Rate this:
Please Sign up or sign in to vote.
Extending RichTextBox with ruler and much more


About two years ago I was creating a project for university. It was a complex of five programs that were related to testing (checking knowledge I mean). One of them contained a text editor. But unfortunately, I didn't know how to do that, that's why it was very simple. So, after these two years, I decided to rewrite my program in C# .NET (initially, it was written in VB.NET) and create a new powerful text editor. You can see part of it here.


I spent a lot of time(!) searching the Internet for controls like this, but the best ones are shareware and others did not fit my needs. So, what does this control have? I tried to make it look like Microsoft Word and I think that there are some similarities. The ruler lets you change the following: left and right margins, left indent, hanging indent and right indent. You also can disable margins (their values are set to 1). You can see how it looks in the picture above.

Also, you can add tabs by clicking on the control with the left mouse button. But it is allowed only inside the area bounded by margins. If you want to remove a tab, just drag it off from the control.

The editor lets you use lists, underline styles, advanced char styles (you can create your own links, that are not words starting with "http://" or even "www"), OLE functionality is also available. I want to thank Oscar Londoño for his article Inserting Images into a RichTextBox Control (The OLE Way). It helped me a lot to deal with OLE. This project contains his code.

Using the Code

You can use the code according to the CPOL.

Projects are created as Windows Applications, but you can easily convert them into *.dll or just embed code into your project.

Unfortunately, I removed Visual Studio 2005, so, sorry but I can't create and upload a Visual Studio 2005 project. But you can import all required files into a Visual Studio 2005 project without any problems. However, note that Visual Studio 2008 added some new namespaces (like LINQ) that Visual Studio 2005 does not "understand". Just remove them. That's all. You are ready.

Points of Interest

One thing that shocked me is that Microsoft has released RichTextBox 6.0! (It is distributed with Microsoft Office 2007) but... with one exception. There is no documentation about its features. All that I've found is a list of added functions. You can find it here. There are also descriptions for all released versions of RichTextBox.


  • 7 January 2008: Initial release
  • 16 January 2008: Projects for Visual Studio 2005 and 2008 posted instead of standalone control.
  • 26 January 2008: Posted completed AdvancedTextEditor project. It is available for Visual Studio 2005 and Visual Studio 2008.
  • 10 February 2008: Fixed PrintDialog bug. It didn't receive focus when shown. Now it's OK. Thanks to Chris Schucker for bug report and recommendations.
  • 22 February 2008: Added new functionality (full text justification, underline styles and colors and other)
  • 24 February 2008: Fixed bug with conversion from millimeter to pixel and vice versa Thanks to Chris Schucker. Also corrected bug which caused incorrect display of the indents.
  • 19 March 2008: Version 2.0 released. A lot of changes including lists, OLE, underline styles, etc.


I understand that I am not able to include everything into the control, that's why you can freely add something useful or change code to fit your needs. But, please inform me about that, just email me at It's just to let anyone use an upgraded (and corrected) version of that control. Of course, advisors will be mentioned.


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


About the Author

Aleksei Karimov
Kazakstan Kazakstan
Currently I am studying at East Kazakhstan State Technical University. My future occupation is engineer-programmer.

I use Visual Basic, C#, Delphi and a little C++. Also I am interested in using SQL and Perl.

You may also be interested in...

Comments and Discussions

Questionquestion Pin
Member 129339424-Jan-17 1:05
memberMember 129339424-Jan-17 1:05 
BugProblem to open Form1.cs Pin
Member 1200134214-Jun-16 4:57
memberMember 1200134214-Jun-16 4:57 
GeneralRe: Problem to open Form1.cs Pin
K. Feroz23-Oct-16 21:09
memberK. Feroz23-Oct-16 21:09 
Questionuse this in MVC4 Pin
Member 1140318429-Jan-15 8:10
memberMember 1140318429-Jan-15 8:10 
QuestionGreat control Pin
Wrangly9-Oct-13 8:14
memberWrangly9-Oct-13 8:14 
QuestionAppearance Modification Pin
Member 101980379-Aug-13 8:42
memberMember 101980379-Aug-13 8:42 
AnswerRe: Appearance Modification Pin
Member 1137284026-Mar-15 7:52
memberMember 1137284026-Mar-15 7:52 
GeneralFabulous Pin
Member 798669131-Mar-13 3:31
memberMember 798669131-Mar-13 3:31 
GeneralMy vote of 5 Pin
sa3dcom18-Oct-12 2:26
membersa3dcom18-Oct-12 2:26 
GeneralMy vote of 5 Pin
rvp717y25-Aug-12 11:22
memberrvp717y25-Aug-12 11:22 
QuestionAbout the IOleObject Interface Pin
Zac Greve17-May-12 9:24
memberZac Greve17-May-12 9:24 
Generalcvgb Pin
Member 85430445-Jan-12 23:12
memberMember 85430445-Jan-12 23:12 
QuestionProblem with adding multiple instance of Advanced Text Editor to a form [modified] Pin
Kondamuru15-Sep-11 12:25
memberKondamuru15-Sep-11 12:25 
QuestionHeader and Footer Pin
Member 794828623-May-11 18:02
memberMember 794828623-May-11 18:02 
Generalvb code Pin
Member 175514922-Mar-11 10:02
memberMember 175514922-Mar-11 10:02 
GeneralTable... Pin
Amer_3mh6-Dec-10 1:19
memberAmer_3mh6-Dec-10 1:19 
GeneralRe: Table... Pin
Aleksei Karimov6-Dec-10 5:41
memberAleksei Karimov6-Dec-10 5:41 
GeneralRe: Table... Pin
Amer_3mh6-Dec-10 6:21
memberAmer_3mh6-Dec-10 6:21 
GeneralRe: Table... Pin
Aleksei Karimov10-Dec-10 5:50
memberAleksei Karimov10-Dec-10 5:50 
Well, as a better solution (maybe) you may look at EM_INSERTTABLE message at MSDN. Oh, sorry, it's not there. Some time ago I found i in Murray Sargent's blog here.

Unfortunately, it also very limited as in functionality as in versions (AFAIR you should use version 4 and above - that means you should load msftedit.dll instead of standard riched20.dll).

You are trying to make a big job (tables in RichEdit). Hope you'll achive desired results. Good luck.

Alex KraS

Generalcan't we add coding support Pin
nethsu4-Oct-10 1:00
membernethsu4-Oct-10 1:00 
GeneralRe: can't we add coding support Pin
Aleksei Karimov5-Oct-10 21:31
memberAleksei Karimov5-Oct-10 21:31 
Generalwow! you are a genius! Pin
zyccld14-Mar-10 7:48
memberzyccld14-Mar-10 7:48 
GeneralRe: wow! you are a genius! Pin
Aleksei Krassovskikh14-Mar-10 9:55
memberAleksei Krassovskikh14-Mar-10 9:55 
GeneralRefresh OLE object Pin
marekpr4-Mar-10 21:01
membermarekpr4-Mar-10 21:01 
GeneralRe: Refresh OLE object Pin
Aleksei Krassovskikh4-Mar-10 21:50
memberAleksei Krassovskikh4-Mar-10 21:50 
GeneralAdvanced Text Editor with Ruler right to left Pin
nyt19722-Mar-10 20:28
membernyt19722-Mar-10 20:28 
GeneralRe: Advanced Text Editor with Ruler right to left Pin
Aleksei Krassovskikh2-Mar-10 20:56
memberAleksei Krassovskikh2-Mar-10 20:56 
GeneralRe: Advanced Text Editor with Ruler right to left Pin
nyt19723-Mar-10 0:14
membernyt19723-Mar-10 0:14 
GeneralRe: Advanced Text Editor with Ruler right to left Pin
nyt197229-Nov-10 21:31
membernyt197229-Nov-10 21:31 
GeneralAdvanced Text Editor with Ruler for Pin
nyt197223-Feb-10 20:38
membernyt197223-Feb-10 20:38 
GeneralRe: Advanced Text Editor with Ruler for Pin
Aleksei Krassovskikh24-Feb-10 8:33
memberAleksei Krassovskikh24-Feb-10 8:33 
GeneralRe: Advanced Text Editor with Ruler for Pin
nyt197224-Feb-10 20:18
membernyt197224-Feb-10 20:18 
QuestionFixed: Doesn't work in X64 and Windows 7 Pin
Alva Chien11-Oct-09 5:36
memberAlva Chien11-Oct-09 5:36 
GeneralRe: Bug found: Doesn't work in X64 platform Pin
Aleksei Krassovskikh12-Oct-09 1:37
memberAleksei Krassovskikh12-Oct-09 1:37 
GeneralRe: Bug found: Doesn't work in X64 platform Pin
Alva Chien12-Oct-09 3:36
memberAlva Chien12-Oct-09 3:36 
AnswerRe: Bug found: Doesn't work in X64 platform Pin
Alva Chien1-Nov-09 6:43
memberAlva Chien1-Nov-09 6:43 
GeneralRe: Bug found: Doesn't work in X64 platform Pin
Aleksei Karimov5-Oct-10 21:43
memberAleksei Karimov5-Oct-10 21:43 
GeneralGreat job just one thing... Pin
ccr0520-Sep-09 8:17
memberccr0520-Sep-09 8:17 
QuestionRuler & Zoom Pin
Ant210019-Aug-09 2:26
memberAnt210019-Aug-09 2:26 
QuestionGreat project, but... Spell check?? Pin
Ant210011-Aug-09 11:01
memberAnt210011-Aug-09 11:01 
AnswerRe: Great project, but... Spell check?? Pin
Aleksei Krassovskikh12-Aug-09 7:42
memberAleksei Krassovskikh12-Aug-09 7:42 
GeneralRe: Great project, but... Spell check?? Pin
Ant210013-Aug-09 1:02
memberAnt210013-Aug-09 1:02 
GeneralGood project Pin
aldo hexosa13-Jul-09 18:16
memberaldo hexosa13-Jul-09 18:16 
GeneralRe: Good project Pin
Aleksei Krassovskikh12-Aug-09 7:43
memberAleksei Krassovskikh12-Aug-09 7:43 
QuestionVB2005 Pin
alpedo2-Apr-09 7:47
memberalpedo2-Apr-09 7:47 
AnswerRe: VB2005 Pin
alpedo3-Apr-09 15:14
memberalpedo3-Apr-09 15:14 
QuestionA minor bug in your control any idea how to fix Pin
Brian Cohen25-Mar-09 6:09
memberBrian Cohen25-Mar-09 6:09 
AnswerRe: A minor bug in your control any idea how to fix Pin
Aleksei Krassovskikh27-Mar-09 5:07
memberAleksei Krassovskikh27-Mar-09 5:07 
GeneralRe: A minor bug in your control any idea how to fix Pin
Brian Cohen1-Apr-09 2:38
memberBrian Cohen1-Apr-09 2:38 
GeneralRe: A minor bug in your control any idea how to fix Pin
frankelman4-Jun-09 22:18
memberfrankelman4-Jun-09 22:18 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 20 Mar 2008
Article Copyright 2008 by Aleksei Karimov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid