Bug: Textbox.Lines.Length returns an incorrect number 
Author Message
 Bug: Textbox.Lines.Length returns an incorrect number

I have a form with a textbox and a button on it. In the click event of the
button I have the following code:

                        Console.WriteLine("Lines before: {0}", txtTest.Lines.Length);
                        this.txtTest.Text += DateTime.Now.ToLongTimeString() + " \r\n";
                        Console.WriteLine("Lines after: {0}", txtTest.Lines.Length);

When I click the button I get the following output in the console:

Lines before: 0
Lines after : 2

If I click the button again I get:
Lines before: 2
Lines after: 3

Why was the txtTest.Lines.Length not 1 after adding a line of text to the
textbox? Intead it went from 0 to 2. Odd. Other than skipping 1 every other
length seems to return correctly.



Sun, 16 May 2004 01:45:48 GMT  
 Bug: Textbox.Lines.Length returns an incorrect number


Wed, 18 Jun 1902 08:00:00 GMT  
 Bug: Textbox.Lines.Length returns an incorrect number
Your program is actually correct:
In the first run, you have line 1 with the date, line 2 is blank, thanks to
the "\r\n" (newline)
On the second run, the date is added to your second line and you add another
newline, resulting in 2 lines with the date on it and one blank line.
If you ran this 10 times, you'd have 11 lines.  10 with the dates and 1
blank line.



Quote:
> I have a form with a textbox and a button on it. In the click event of the
> button I have the following code:

> Console.WriteLine("Lines before: {0}", txtTest.Lines.Length);
> this.txtTest.Text += DateTime.Now.ToLongTimeString() + " \r\n";
> Console.WriteLine("Lines after: {0}", txtTest.Lines.Length);

> When I click the button I get the following output in the console:

> Lines before: 0
> Lines after : 2

> If I click the button again I get:
> Lines before: 2
> Lines after: 3

> Why was the txtTest.Lines.Length not 1 after adding a line of text to the
> textbox? Intead it went from 0 to 2. Odd. Other than skipping 1 every
other
> length seems to return correctly.



Sun, 16 May 2004 02:11:26 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. system call to return current line number

2. system call to return current line number

3. system call to return current line number

4. How to do a line feed in a multi-lined TextBox

5. Textbox Length

6. How to control whitespace length for Tab in Multiline textbox

7. Return value incorrect?

8. CreateFile returns Error_invalid_parameter - the parameter is incorrect.

9. CTimeSpan reports incorrect number of days

10. ifstream read incorrect number of bytes

11. sin and cos return incorrect values

12. sin and cosine return incorrect values..

 

 
Powered by phpBB® Forum Software