We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to determine the number of lines in a textbox

Some body know how to count the no of lines in a textbox in VB.Net? A "line" is defined as each new line after a word-wrap, in other words, each line showing against the left margin. It does not mean, and is independent of, the actual number of lines delimited by hard returns in the text.

5 Replies

CB Clay Burch Syncfusion Team July 4, 2002 09:47 AM UTC

With a TextBox, other than trying to implement a wordwrap algorithm yourself, and count the wraps in the process, I don't know of a way to get this value. If you use a RichTextBox, you can probably use its GetPositionFromCharIndex to compute the number of wrapped lines. Worst scenario is you could do a loop from 1 to Length of the string and just count the number of times the Y index changed. More efficient might be to get the difference between the Y of the last character and the Y of the first character and then divide by the row height. this.label1.Text = this.richTextBox1.GetPositionFromCharIndex( this.richTextBox1.Text.Length).ToString(); this.label1.Refresh();


AN Anonymous July 4, 2002 09:13 PM UTC

Thanks Clay


AN Anonymous July 4, 2002 09:15 PM UTC

Thanks Clay


AN Anonymous July 4, 2002 09:15 PM UTC

Thanks Clay


AD Administrator Syncfusion Team July 7, 2002 11:03 PM UTC

> With a TextBox, other than trying to implement a wordwrap algorithm yourself, and count the wraps in the process, I don't know of a way to get this value. Could you use Graphics.MeasureString()?

Loader.
Live Chat Icon For mobile
Up arrow icon