|
|
Comments and Discussions
|
|
 |

|
Very good job, totally awesome.
|
|
|
|

|
I'm happy you like it -- Thank you kindly, Yanick Lafontaine
|
|
|
|

|
The CPOL licence under which this code is currently released is incompatible with the Free Software Foundation's GPL licence and it is not approved by the Open Source Initiative. Long story short this means that your excellent code cannot be used (legally) in 99% of all of the open source projects out there, virtually all of which use either GPL or an OSI licence.
The reason that the CPOL is not comparable with standard open source licences is that it contains crazy restrictions such as "You agree not to use the Work for illegal, immoral or improper purposes" - what's an immoral purpose? This prohibition basically makes the licence useless, because no two people will ever agree on what an immoral or improper purpose is.
If you want as many people as possible using your code please consider releasing it under one of the standard open source licences, the two most commonly used ones are GPL and BSD.
While there are many excellent articles online discussing the differences between the two, the bottom line is that you want to choose the GPL if you want your code to only be used in open source software and you want to use the BSD if you want everyone including businesses that make proprietary software to be able to use your code.
Thanks for writing this control. I hope you will release it under a standard open source licence of your liking.
|
|
|
|

|
very usefull thanks a lot
|
|
|
|

|
I'm glad you like it -- thanks, ZangetsuZ
|
|
|
|

|
Hi,
I use this control very often and I like it!
But, a question:
Do you have any idea, if you can enhance the control for the using with TextBox or/and ListBox too?
Regards
Dietrich
|
|
|
|

|
Hi dherrmann I'm glad you like it!
I guess it shouldn't be too hard to adapt the code so that a regular TextBox can use it too, but a TextBox' lineheights are always the same (as with a ListBox) so a significant part of the code would no longer be needed, I think.
The lineheights and the location of the parentcontrol are really the only things that need to be given to the linenumbering control.
|
|
|
|

|
Just want to comment on your great work. I like the fact that it is a separate control to the RichTextBox!
|
|
|
|

|
Thanks, nguyenphuphi, I'm glad you like it
|
|
|
|

|
...too bad I can not use it.
Because I dont have any .NET. Only Visual Basic 6...
I've been working on a code editor in Visual Basic 6 for several months, and it's almost finished, except that I dont have a proper linenumbering feature yet. I have had a hard time trying to apply line numbering to the RTB in a way that looks good. I've tried many different things, including sub classing and painting linenumbers in a picturebox, but due to the smooth scrolling of RTB, it doesnt align properly when scrolling etc.
I wonder, is it possible to port your linenumber class to Visual Basic 6?
I would be very happy if you could help me solve my problem. (Banging my head into the wall for months trying to fix the linenumbering, is not fun)
Thanks in advance!
Yours Sincerly,
Nosferatu
|
|
|
|

|
Hi Nosferatu,
Unfortunately, I never really used VB6 (I coded mostly in VBA for AutoCad) so I have no idea of what parts of the code can be backported to it
A large part of the logic in my program is based on working around the RTB's quirky/flawed .lines array which becomes incomplete when lines of text are wrapped. A VB6 RTB may not even have those quirks.
I believe the coordinate system in VB6 differs from that in VB.NET so if you're trying to use that part of my code directly, it may cause misalignment.
This program was a learning project for me too, so if I were to redo it today, it would probably look even more .NET-ish than back when I made it.
I'm assuming you know most of these, but mentioning them anyway: VB6 resources[VB6 resources]
|
|
|
|

|
Hi nogChoco
Thanks for the reply. I know most of the VB6 Resources, and one will mostly find newbie questions there (like how to change the color of a label or simular). I've searched and searched. Found a few bad attempts to add Linenumbers to RTB, which does not work, and by the way look ridiculous.
The RTB for Visual Basic 6, does not have any linenumbers, or much else. I've read that Microsoft attempted to add more features to the .Net RTB, including linenumbers, but that they left it half finished, and that's probably what you mean by "quirky/flawed".
Is your code dependent on that quirky .Net RTB, or could one use a VB6 RTB without any linenumber feature?
I have a feeling that VB6 is very limited compared to the .Net version, and that it may be impossible to port all of your code (and features) to VB6, but I've started an attempt to port it now. And I think I found a small bug in your code (the linenumber class):
' --- Memory CleanUp
If zPen IsNot Nothing Then zPen.Dispose()
If zBrush IsNot Nothing Then zPen.Dispose()
Shouldnt it be:
' --- Memory CleanUp
If zPen IsNot Nothing Then zPen.Dispose()
If zBrush IsNot Nothing Then zBrush.Dispose()
Anyway, I wonder if you are willing to assist me in the porting attempt, and if you can email me or something.
Thanks in advance.
Yours sincerly,
Nosferatu
|
|
|
|

|
Ah, yes, that looks like a copy/paste bug
I never worked with classes or graphics in VBA (as the output in AutoCAD was graphical anyway), so I don't think I can be much help to you, to be honest.
In VB.NET, the RTB gives the location for each line and each character's top-left corner. If the VB6 one does that too, then you should be able to do what I did, although probably with less fancy graphics as .NET uses GDI+, and perhaps the drawing and RTB's location-polling speeds may not be as fast.
The quirky .Lines array meant I couldn't just trust the position of the .Lines and had to find the first character of each real line myself. Looking back at the code, it's probably not that big a deal though it likely took me the most thought (counting linebreaks to find the right line instead of just using .Lines).
In essence, the RTB and LineNumbers are only linked by computing where the .Y location of the RTB's first character is, in the LineNumbering control. I compute that by converting the RTB's coordinates to screencoordinates and then to the LineNRs coordinates, but as I said: the coordinate system is different in VB6 so that will probably need rethinking - it's possible that you don't even have to convert and can just use the same .Y height in both RTB and LineNRs.
After you have that .Y offset, it's just a matter of getting the position of each visible RTB line's first character and drawing a LineNR on the same height.
|
|
|
|

|
Great! I love it! Thanks for this control
Check out my desktop conversion software for Windows -
www.universalconverter.net
|
|
|
|

|
Thank you for your compliment, Ant2100 -- enjoy the code
|
|
|
|

|
Compiled to assembly to include in a C# project and it all just worked, no fuss. Simple and elegant.
Got to be one of the most useful controls on CodeProject.
Thanks!
Rob
|
|
|
|

|
Hi Rob, thank you for your compliment -- I'm happy you found it a useful control
|
|
|
|

|
Excellent article! Anyone know of a C# equivalent of this though? I find it very interesting but unless it can be converted to C# (I've made many attempts and failed), I won't be able to use it.
Anyways, great job.
|
|
|
|

|
I've converted this code to C# and use in some of my projects.
You can find the converted code in this [article]. Just download the source and take a look at the LineNumbers.cs file.
|
|
|
|

|
the link u gave is not working for c#..
can u pls help me
|
|
|
|
|

|
I have under VB2008 Express a large Project with Multitab-Editor. I'm reading your Text and I don't check the second Block of "Using the Code".
1. I have unzipped the Files and i'm copy the File: LineNumbers_For_RichTextBox.vb in my Project.
2. I have build my Project by click (I have the German Version of VB2008) "Erstellen, MLT2007 Erstellen". After the Build i can't see any Change in the Toolbox!
When i add the Class-Code via "Project, existing Element add" the VB2008 Express displays two Errors.
Fehler 1 Der Typ "List" ist nicht definiert. LineNumbers_For_RichTextBox.vb 69 26 MLT-2007NET
Warnung 2 Name "_SeeThroughMode_" ist nicht CLS-kompatibel. LineNumbers_For_RichTextBox.vb 155 77 MLT-2007NET
In my existing Project i can't Insert your Class! The two Error-Messages are displayed.
When i create a new Project that i can Insert your Class. That's absolute bad! I can't start my Project new!
Exist this Control as the other Controls that i can Insert to the Tool-Box?
Can I create your Control under Runtime per Code? I create the RTF-Boxes under Runtime per Code and i don't have on my MDI-Window any RTF-Boxes when my Program starts. The RTF-Boxes are created on Tab-Registers on Runtime.
modified on Wednesday, August 20, 2008 4:31 PM
|
|
|
|

|
Hi RogerBerglen,
The easiest way to add it to your project, would be by selecting 'Add Class' from the Project menu, then copy/paste the code from LineNumbers_For_RichTextBox.vb into that new class tab (overwriting the small 'Public Class Class1, End Class' code that is already there), and then rebuilding the project.
When you then select a form's design tab, you should see a section in the toolbox called 'YourProjectName Components' and the 'LineNumbers_For_RichTextBox' will be listed there like a normal control (you can use it via code too).
The 'Der Typ "List" ist nicht definiert' error sounds like the 'System.Collections.Generic' namespace isn't imported into your project yet.
The second error about CLS-compatibility is hard for me to judge, as I assume it depends on how strict the compatibility checks are. The only thing different about that line 155, is the fact that it is written with underscores (I just did that to make it stand out in the property-listing). Maybe rename that _SeeThroughMode_ property (and each call to it)?
|
|
|
|

|
I have Test to Add the Control on my Editor only per Code. And i can't not see the LineNumberControl when my Program run.
When i place the Control from the Toolbox on a RichTextBox then i can see the LineNumbers. What' wrong?
The Code:
Private Shared ZeilenNr(0) As LineNumbers_For_RichTextBox
Z = 0
For Z = 0 To SeitenDa.Length
If SeitenDa(Z) = False Then
A = Z
If Z + 1 = SeitenDa.Length Then
ReDim Preserve Edit(Edit.Length)
ReDim Preserve ZeilenNr(ZeilenNr.Length)
End If
Exit For
End If
Next
ZeilenNr(A) = New LineNumbers_For_RichTextBox
Edit(A) = New RichTextBox
Edit(A).Size = New Point(Rahmen(A).Width - 18, Rahmen(A).Height - 21)
Edit(A).Left = 12
Edit(A).Top = 14
Edit(A).Name = "Editor" + A.ToString
Edit(A).BorderStyle = BorderStyle.None
Edit(A).Multiline = True
Edit(A).ContextMenuStrip = Desktop.EditContext
Edit(A).Font = New Font("Courier New", 10)
Edit(A).AcceptsTab = True
Desktop.EditorTab.TabPages.Add((A).ToString, "Neu" + (A).ToString, 0)
Desktop.EditorTab.SelectTab(A)
Desktop.EditorTab.TabPages(A.ToString).Controls.Add(Edit(A))
Desktop.EditorTab.TabPages(A.ToString).Controls.Add(ZeilenNr(A))
ZeilenNr(A).ParentRichTextBox = Edit(A)
The Code put on a Tab a RichTextBox, a Frame around the Richtextbox and the LineNumberControl.
The LineNumberControl will be not displayed. Have i forgotten Anywhere??
Have you a Demo-Code to create your Control on Runtime on a Tab-Control?
|
|
|
|

|
It seems to be a combination of 2 problems with my control: the width wasn't being set properly (so width=0 and that made it lose its region, I think), and there is also an initial sizing that was forgotten - my control wasn't resizing until there was a contentresize on the parent RichTextBox.
For the width problem, simply put a "Me.Width = 1" line in the New() constructor so that it looks like this:
Public Sub New()
With Me
.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
.SetStyle(ControlStyles.ResizeRedraw, True)
.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
.SetStyle(ControlStyles.UserPaint, True)
.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
.Margin = New Padding(0)
.Padding = New Padding(0, 0, 2, 0)
End With
With zTimer
.Enabled = True
.Interval = 200
.Stop()
End With
Me.Width = 1
Me.Update_SizeAndPosition()
Me.Invalidate()
End Sub
And for the intial sizing problem, add a "zContentRectangle = zParent.ClientRectangle" line to the ParentRichTextBox property setter, so that it looks like this:
Public Property ParentRichTextBox() As RichTextBox
Get
Return zParent
End Get
Set(ByVal value As RichTextBox)
zParent = value
If zParent IsNot Nothing Then
Me.Parent = zParent.Parent
zContentRectangle = zParent.ClientRectangle
zParent.Refresh()
End If
Me.Text = ""
Me.Refresh()
Me.Invalidate()
End Set
End Property
(and don't forget to leave some room next to your richtextbox so that the LineNumbers control can show up there)
That should solve the problem, I think Sorry for the inconvenience
|
|
|
|

|
Thank you for the fast answer! That's a Service, Great! I will test your Codechanges. Im good Luck to see the Line-Numbers on my MultiTab-Editor.
|
|
|
|

|
I write a simple Programregion in my Project. The Code place a Child-Window with a RichTextBox on my MDI-Window. Unfortunally the LineNumbers are not displayed ! I have made your Changes before i write the Test-Code.
Here is the Test-Code:
Public Class Editor
Private Sub Editor_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim Test As New LineNumbers_For_RichTextBox
Test.ParentRichTextBox = Me.RichTextBox1
Test.AutoSizing = True
Test.BackgroundGradient_AlphaColor = Color.White
Test.BackgroundGradient_BetaColor = Color.LightSteelBlue
Test.BackgroundGradient_Direction = Drawing2D.LinearGradientMode.Horizontal
Test.BorderLines_Color = Color.SlateGray
Test.BorderLines_Style = Drawing2D.DashStyle.Dot
Test.BorderLines_Thickness = 1
Test.DockSide = LineNumbers_For_RichTextBox.LineNumberDockSide.Left
Test.GridLines_Color = Color.SlateGray
Test.GridLines_Style = Drawing2D.DashStyle.Dot
Test.GridLines_Thickness = 1
Test.LineNrs_Alignment = ContentAlignment.TopRight
Test.LineNrs_AntiAlias = True
Test.LineNrs_AsHexadecimal = False
Test.LineNrs_ClippedByItemRectangle = True
Test.LineNrs_LeadingZeroes = True
Test.Visible = True
Me.Controls.Add(Test)
End Sub
End Class
|
|
|
|

|
After some testing, I think the problem occurs when there is not enough room to display the LineNumber items fully: if the control's location.X is negative, which means only a part of the linenumber-items would show, then the linenumber-item(s) are considered as totally invisible, and then the empty control no longer shows, of course. It only seems to happen at the initial sizing of the control, though, which is a bit weird.
I probably coded it that way to speed up the drawing of items, with this unfortunate side-effect as a result. For now, I can only suggest to leave enough room for the control, as I can't give you reworked code at the moment :(
|
|
|
|

|
Thank you very much for this tool.
I was building it myself (and not succeeding very well) and by accident stumbled upon this.
Thank you very very much for this code.
I love it.
|
|
|
|

|
Thank you for the compliments - Have fun with the code!
|
|
|
|

|
Hi,
Can you send its C# version on my mail : naveenrhl@yahoo.com
Thanks
Navin
always care for physics
|
|
|
|

|
Hi
I m using this code in my Code editor project, nice code. but i feels when I am working with large files then it delaying in refreshing and display line numbers.
can you help me how to over come this problem.
Regards
Praveen kaushik
|
|
|
|
|

|
I think this is exactly what I need for my text editor I was planning to build. Good Job! What about adding search function?
|
|
|
|

|
Hi computergeek101,
I have no further plans with this control, but you have the source-code so feel free to use it as you please
|
|
|
|

|
This is by far the best line number control i have seen. However, i do have a question.
I am developing a Code Editor programme for my work, and one of the feature is use code folding. Now, how do i implement code folding with this control?
So, if i am to fold the code between line number 25 to 37 in my rtf control, so i only want to show line number 1 to 24, and 38 to say 50, how do i make the call to the line number control?
Thanks
Cecil
|
|
|
|
|
|

|
Thanks for your compliment, American_Eagle
|
|
|
|

|
I've found that if you resize the window to be smaller (e.g. make the window scroll to line 5 in your example) then the scrolling height doesn't change until you have dragged the scrollbar at least once, which then recalculates the correct scrolling height.
|
|
|
|

|
Thanks for your feedback, frumbert
It seems to be a RichTextBox bug, though: I removed the linenumbers and the RTB's scrolling did not calculate properly either.
|
|
|
|

|
Hi, First of all, its really cool control and great job!!..
and lots of thanks for sharing it.
I as looking for a similar control, but in C#. so I have converted your code to C# using a conversion util and did little fix after conversion. Also, I have included your name/article reference in Credits.
Thanks,
Vivek
|
|
|
|

|
Thanks for the compliment and the credits, Vivek
|
|
|
|

|
I also would like a C# version of this, is there any chance of you posting the conversion that you made?
Thanks.
Matthew
|
|
|
|

|
Compile to DLL and include it in your C# App
Milan Schoemig
Milan.Net
|
|
|
|

|
There is a minor problem. When my application minimizes to systemtray (user option) the I get a "Parameter is not valid" error message in the following procedure (on line OnHandleCreated(e)).
Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
MyBase.OnHandleCreated(e)
Me.AutoSize = False
End Sub
Otherwise, this is a great control.
Thank You
|
|
|
|

|
Hi BeLHold, thanks for your compliment and comment
I don't know why that line would cause a problem, as it's a standard call, but you can remove that sub altogether anyway. Originally, I inherited from 'Label' instead of 'Control', and overriding this sub was meant to counter the Label's default autosizing. I hope that will solve it, but as I don't know where the problem lies, I can't be sure.
|
|
|
|

|
Update B is now available for download - it's got some important improvements that should double the performance speed.
Instead of immediately calculating the item's height, the Update_VisibleLineNumberItems() method now builds a list of LineNumbers with their locations first, and computes the lineheights afterwards by comparing those locations. This halves the number of calls to the RTB's slow .GetPositionFromChar() method (which gets slower with each line added to its text), so the performance is doubled.
A timebased cutoff is now also being used during scrolling, to keep the computations from interfering with the scrollingspeed. There will still be at least one LineNumberItem visible, though, so when the document gets very big (multiple thousands of lines), the computation of that one item may start to cause a noticeable delay again (the RTB itself is responsible, though).
Get it while it's hot
|
|
|
|
|

|
Hey. Great job!
I will use this for my project, and give you credit. I've been looking something like this for few month last year and it has finally come!
Thanks,
Keehun
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
LineNumbers that dock to a RichTextBox or show as an overlay on top of it.
| Type | Article |
| Licence | CPOL |
| First Posted | 5 Apr 2007 |
| Views | 89,395 |
| Downloads | 1,199 |
| Bookmarked | 95 times |
|
|