Hi,
is there a (simple) way to determine how many lines there are in a rich text box that has multiline set to true and only one fontsize (though it may have some styles like bold and italic)?
If I use the RichTextBox.TextHeight property, it seems to return the number of paragraphs * textheight. A paragraph can be split into multiple lines with word-wrap. I need to find a way to calculate the number of lines (including blank lines) so that I can resize the rich text box to fit all the text inside (I resize it vertically).
I can do this by adding all the separate words in a rtf to a string, then checking after every word to see if the textwidth exceeds the width of the rtf. Then back-up one word and loop untill last word. But I'd have to do that for every keystroke the user gives me. Wouldn't that be too slow?
What I do now is to divide the width of a paragraph by the width of the rtf, but that does NOT take into account lines that end before the very right margin of the rtf box. On some occasions this creates a textbox that is higher/longer than it should be.
Any ideas how to tackle this? Anything at all would be welcome!
Hokje
when there's too much something is missing
is there a (simple) way to determine how many lines there are in a rich text box that has multiline set to true and only one fontsize (though it may have some styles like bold and italic)?
If I use the RichTextBox.TextHeight property, it seems to return the number of paragraphs * textheight. A paragraph can be split into multiple lines with word-wrap. I need to find a way to calculate the number of lines (including blank lines) so that I can resize the rich text box to fit all the text inside (I resize it vertically).
I can do this by adding all the separate words in a rtf to a string, then checking after every word to see if the textwidth exceeds the width of the rtf. Then back-up one word and loop untill last word. But I'd have to do that for every keystroke the user gives me. Wouldn't that be too slow?
What I do now is to divide the width of a paragraph by the width of the rtf, but that does NOT take into account lines that end before the very right margin of the rtf box. On some occasions this creates a textbox that is higher/longer than it should be.
Any ideas how to tackle this? Anything at all would be welcome!
Hokje
when there's too much something is missing