|
|
Comments and Discussions
|
|
 |

|
but can i do it without using the reference tool?
and just a code?
|
|
|
|

|
Will this work under VS11? I've added a reference to VSB but can't seem to add linenum_rtf.cs under existing items.
|
|
|
|

|
It is very good! But I still have problems with displaying line numbers with big text files :(
|
|
|
|

|
When i add the files and rebuild i get this:
Error 1 Program 'C:\Users\{username}\Documents\Visual Studio 2008\Projects\c#\luaediter\Lua Editer\obj\Release\Lua Editer.exe' does not contain a static 'Main' method suitable for an entry point
i am using Visual C# express 2008. Any ideas?
|
|
|
|

|
Does you custom control have some type of license or can people use it for personal and commercial use free?
|
|
|
|

|
Go for it! The only thing i ask is a small line of some sort of, "thank you" in the credits.
Please let me know of the product that it is being used in (even if the code was re-vamped and changed). This way I can post Success Stories/Projects. In return this can possibly help generate more traffic or recognition for you.
Best of luck to you and your project!
- Damian
-code monkey-
|
|
|
|

|
OK cool, I'll let you know shortly if I decide to use it.
|
|
|
|
|

|
Consider putting this control into a small project on codeplex.com.
You'd then be able to accept patches from people, and apply changes, accept and manage change requests, do versioning, and so on.
It sounds like a whole lot of extra work, but it's really not, after you get it set up.
|
|
|
|

|
I noticed that the line numbers seemed to disappear when I displayed an RTB with hundreds of lines. ??
I looked in Update_SizeAndPosition() and found that the edge of the linenumbers control was being moved outwards, either left or right, depending on how it was docked to the parent RTB. When there were, say, 4 digits to display, and the linenumbers control was displayed on the left, the left edge of it would move further leftward. This became a problem when the control was anchored to the left edge of the form.
So I reworked the Update_SizeAndPosition() method, based on the principle that the bounding box of the linenumebers control plus its parent should not change, regardless of how wide the digits display could become. In other words, when docked to the left of the RTB, the left edge of the linenumbers control should never move further leftward, and the right edge of the RTB should never move further rightward.
Conversely, when docked to the right edge of the RTB, the right edge of the linenumbers control should nevevr move further rightward, and the left edge of the RTB should never move further leftward. If that makes sense.
The only movement, then, should be on the internal borderline, between the two controls. As the linenumbers control needs to expand, the RTB should shrink, horizontally.
The modified code looks like this:
else if (zDockSide != LineNumberDockSide.None)
{
zNewLocation.Y = zParent.Top;
zNewSize.Height = zParent.Height;
if (zAutoSizing_Size.Width > 0)
zNewSize.Width = zAutoSizing_Size.Width;
int delta = zNewSize.Width - this.Size.Width;
if (delta == 0) return;
var newParentSize = zParent.Size;
newParentSize.Width = newParentSize.Width - delta;
if (zDockSide == LineNumberDockSide.Left)
{
var newParentLoc = zParent.Location;
newParentLoc.X = zNewLocation.X + zNewSize.Width + 1;
zParent.Location = newParentLoc;
}
else if (zDockSide == LineNumberDockSide.Right)
{
zNewLocation.X = this.Location.X - delta;
}
zParent.Size = newParentSize;
this.Location = zNewLocation;
this.Size = zNewSize;
}
|
|
|
|

|
Thank you for the update! Testing it out now. I'm still unhappy with the overall update mechanism in general. Don't get me wrong, your contribution was awesome!
Going to look into different routes of updating the line count with as little over-head as possible. As we all noticed, it begins to choke a little after ~15000 lines.
-code monkey-
|
|
|
|

|
Damian, after looking at this further, I thought to try a different tack.
Rather than defining a companion control, as you did here, I extended RichTextBox. This RichTextBoxEx displays line numbers itself, within its bounds, in response to the Paint event. Some pictures.
http://i39.tinypic.com/13zcoz6.jpg[^]
http://i43.tinypic.com/wml2z9.jpg[^]
http://i39.tinypic.com/25i4x3o.jpg[^]
It scrolls cleanly, it's fast.
You can get the code to see what I did, here:
http://xpathvisualizer.codeplex.com/SourceControl/changeset/view/42057#823009[^]
Also this one is under source control, so if anyone wants to submit requests or bugs, it's available to you.
|
|
|
|

|
First of all, great work Really helped me a lot
But there are two minor bugs in your code:
1. If the first character is a New-Line, the first line number is "2" instead of "1". I fixed it by changing
private int FirstVisibleTextLine
{
get
{
int c = GetCharIndexFromPos(1,1);
for (int i=0; i < CharIndexForTextLine.Length; i++)
{
if (c < CharIndexForTextLine[i]) return i;
}
return CharIndexForTextLine.Length;
}
}
to
private int FirstVisibleTextLine
{
get
{
int c = GetCharIndexFromPos(1,1);
for (int i=0; i < CharIndexForTextLine.Length; i++)
{
if (c <= CharIndexForTextLine[i]) return i;
}
return CharIndexForTextLine.Length;
}
}
(replacing c < by c <=) - I have not tested this exhaustively, but I didn't face any problems with this solution so far.
2. If the line-numbers increase the number of digits (e.g. from 9 to 10), the size of the line-number-space is not calculated correctly. If you add another line (e.g. from 10 to 11), it works as expected.
As a solution, I changed
private int LineNumberWidth
{
get
{
if (_lnw > 0) return _lnw;
if (NumberLineCounting == LineCounting.CRLF)
{
_ndigits = (CharIndexForTextLine.Length == 0)
? 1
: (int)(1 + Math.Log((double)CharIndexForTextLine.Length, 10));
}
}
to
private int LineNumberWidth
{
get
{
if (_lnw > 0) return _lnw;
if (NumberLineCounting == LineCounting.CRLF)
{
_ndigits = (CharIndexForTextLine.Length == 0)
? 1
: (int)(1 + Math.Log((double)CharIndexForTextLine.Length+1, 10));
}
}
(adding a "+1" before calculating the log10, because _n-New Line's correspond to _n+1 displayed lines)
Hope that helps
Cheers
Pascal
|
|
|
|

|
I cant find the control for the LineNumbers
I am using Visual C# 2008 Express Edition,
I have added a reference for Microsoft VisualBasic,
I have added the linenum_rtf.cs
So why doesn't it show?
|
|
|
|

|
Did you check the requirements over all of the requirements? The most common mistake made by most is, You must compile your program after adding the file & the reference. After that, the control will be visible and able to be used.
One side note, this was never tested under Express Edition. If you do not have the funds or means to have a full version of Visual Studio (2005/2008/2010) feel free to try, SharpDevelop at www.icsharpcode.net It is a completely free, full packed alternative to MS Visual Studio.
Best of luck to you, hope this helps
- Damian-code monkey-
|
|
|
|

|
replace: DateAndTime with DateTime
insert: string CrLf = Environment.NewLine;
replace: Constants.vbCrLf with CrLf
replace: Strings.Chr(10) with (char)10
delete: using Microsoft.VisualBasic;
|
|
|
|

|
thank you for your feedback & hints
-code monkey-
|
|
|
|

|
When I load about 27k lines, there is good bugs. Programm work very slowly. How can I fix it?
sorry for my english.
|
|
|
|

|
that was heavily looked into.. ran a debug on a few of the recursive functions & it does call itself a lot! The issue lies when trying to get the sum & individual height of each line in the file. If this was a fixed height box like most code boxes, this issue wouldn't arise.
I am always open to suggestions! Maybe if we had the RTF box set as a fix-font, this would help lower the impact of this issue.
-code monkey-
|
|
|
|

|
I looked into this as well. Found that the TextChanged() method gets called very very often. I had coupled this with a RTB that was displaying XML, and also formatting the XML with syntax highlighting. With every format change, the zParent_Changed method was being invoked, which then invalidated the control and caused a repaint.
That didn't work out so well. Definitely need a way to distinguish between types of changes and be more intelligent about re-painting. It's possible you could use a backoff timer. If you get 72 zParent_Changed() calls in a row, wait.... until they stop coming. And only do the refresh/invalidate after a short delay when no further zParent_Change events occur. Haven't tested this, it's only an idea.
The other thing: inside Update_VisibleLineNumberItems(), there are a number of things that can be easily optimized. For one thing, every retrieval of zParent.Text is expensive. So, retrieve it once at the top of the method and replace all zParent.Text with a reference to the local copy. Like this:
if (zParent == null)
return;
string txt = zParent.Text;
if (string.IsNullOrEmpty(txt))
return;
...
For another thing, the timer in that method is sort of odd. It's very simple to replace it with a stopwatch. Not sure if that's a performance thing, but it makes the code cleaner.
var stopwatch = new Stopwatch();
stopwatch.Start();
....
if (zParentIsScrolling == true && stopwatch.ElapsedMilliseconds > 500)
{
Finally, counting the lines is done via a call to String.Split() , which produces an array of strings. Then the .Length property is retrieved on that array.
zSplitStartLine = Math.Max(0, zParent.Text.Substring(0, zStartIndex).Split("\r\n".ToCharArray()).Length - 1);
This is very inefficient, if all you want to know is how many \n characters are in the string. Replace that with a simple utility method that iterates through the chars of the string.
private static int CountNewlines(string s)
{
int len = s.Length;
int c = 0;
for (int i=0; i < len; i++)
{
if (s[i] == '\n') c++;
}
return c+1;
}
...
zSplitStartLine = Math.Max(0, CountNewlines(txt.Substring(0, zStartIndex)) - 1);
With these changes, the control is much more usable for me for RTB's with larger content.
Thanks for the control, though. Very very useful.
|
|
|
|

|
I used this Control and it is very good. But I still have problems with displaying numbers of lines with big text file. I made changes described in previous answer without counting zParent_Changed().
I have a text file with more then 1000 of lines, 50-100 characters in line.
What can I do to adjust performance? Can this counting zParent_Changed() help this much?
|
|
|
|
|

|
Are there any ways to get the line number when I click on the control?
Thanks~
|
|
|
|
|

|
Just getting ready to use that control, and thanks for getting it ready for me.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Display line numbers for rich text box with auto sizing. This is a converted version from another article written in VB.NET.
| Type | Article |
| Licence | CDDL |
| First Posted | 9 Aug 2009 |
| Views | 40,319 |
| Downloads | 2,519 |
| Bookmarked | 56 times |
|
|