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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to determine the number of lines in a textbox

Thread ID:

Created:

Updated:

Platform:

Replies:

541 Jul 4,2002 05:25 AM UTC Jul 7,2002 11:03 PM UTC Windows Forms 5
loading
Tags: FAQ
Anonymous
Asked On July 4, 2002 05:25 AM UTC

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.

Clay Burch [Syncfusion]
Replied On 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();

Anonymous
Replied On July 4, 2002 09:13 PM UTC

Thanks Clay

Anonymous
Replied On July 4, 2002 09:15 PM UTC

Thanks Clay

Anonymous
Replied On July 4, 2002 09:15 PM UTC

Thanks Clay

Administrator [Syncfusion]
Replied On 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()?

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;