Introduction
Please wait while more details are being updated.
This article is a converted project from VB.NET to C#, originally created by nogChoco in the article, "LineNumbers for the RichTextBox".
Sure anyone can make a line numbering user control. I've made many variations of them for VB 3.0 to 6.0 & C++, always using picture boxes or whatever as a drawing base to mark the position. When Microsoft released the newer versions of RichText
control boxes (in more recent versions), the old methods went out the door. By this, I mean that one can easily zoom in & out of the box by holding down Ctrl (or Shift) key while using the mouse wheel, posing a HUGE problem for traditional methods.
Q: Why use RichText
instead of the traditional TextBox
?
A: (In older versions) RichText
can hold more data! (and offers more features)
Before Compiling Fore-note
I have successfully compiled & ran this example project under both Visual Studio 2008 & SharpDevelop 3.x using Framework 2.0.
You will probably have problems running this example project under VS 2005 & lower; do note the control does work under the Framework 2.0. If you are having problems running this under VS 2005 or other studios, you might want to either find yourself a project converter or upgrade your studio. I am very sorry if this is an inconvenience for you, that is why this is posted for Intermediate & Expert users.
If you want a free IDE that can run this, try out SharpDevelop IDE.
Compiling Your Own Project
Using SharpDevelop (3.x)
- Create a new C# Windows project
- Add Reference to your project (Right click 'References' > 'Add Reference')
- Under GAC Tab select: "
Microsoft.VisualBasic
"
- Insert into your project existing item.. "linenum_rtf.cs"
- Under Custom Components, insert "
LineNumbers_For_RichTextBox
" into your form as well as insert a RichTextBox
- Line them up side by side (left side by default)
- Link Line Numbers to your
RichTextBox
- Under "Add LineNumbers to" > "Parent Rich Text Box":
- Select your
RichTextBox
to add line numbers to
- (feel free to customize it on your own)
- Run the project!
Using Visual Studio (2008)
- Create a new C# Windows Project
- Add Reference to your project (Right click 'References' > 'Add Reference')
- Under .NET Tab select: "
Microsoft.VisualBasic
"
- Insert the existing item into your project... "linenum_rtf.cs"
- Build your project!
- This will not show under Custom Components unless you build you the project first!
- Under Custom Components, insert "
LineNumbers_For_RichTextBox
" into your form as well as insert a RichTextBox
- Line them up side by side (left side by default)
- Link Line Numbers to your
RichTextBox
- Under "Add LineNumbers to" > "Parent Rich Text Box":
- Select your
RichTextBox
to add line numbers to
- (feel free to customize it on your own)
- Run the project!
Background and Points of Interest
As a software designer/developer like all of you, time is of the essence when meeting deadlines! This example using the RichText
control works great! Especially with the zoom in/out feature using the mouse wheel, and it added nice graphical features which can be easily customized. However, I feel the urging need to program in C# and this example was only provided in VB.NET... It was time to upgrade it & now, on with the show!
History
- 2009.08.05 - Initial conversion from VB.NET to C#
- 2009.08.08 - Updated notes on this page (pictures soon to come)
To Do
- Provide 2 versions
- Graphical: The current version (customizable and beautiful)
- Simple: Side bar is simple & has low overhead on your projects
- Strip out references to
Microsoft.VisualBasic
so it's more pure C#
- Damian J. Suess of Xeno Innovations, Inc. [2000-2009]