I have a problem with a passing resemblance to the one found on these forums in
this thread.
I'm using a RichTextBox to display an (in most cases short) article (to take advantage of RichTextBox's advanced formatting capabilities). The RichTextBox being displayed outside the screen area is not a problem, as the box is located inside a control with a scrollbar, so the article itself should not have a scrollbar.
Now, I need to determine the height needed for the RichTextBox, so that the article will be displayed in its entirety. The basic approach would be to determine the number of lines in the article, and then multiply that by the line height, but multiplying a line number by a set height won't take into account headers, or other occurences with special formatting that might increase the line height.
I realize this won't really be a problem in most cases, if I give the box a bit of an error margin, but I'd like to be as general as possible about this, as I might be using the control later on, for larger articles. Before I start thinking about writing some monstrously complex (and inefficient) parsing code, I was wondering if anyone around here had any ideas as to how to take into account the individual heights of lines (or at least the height of lines that does not conform to some sort of "standard" line height), with some semblance of efficiency in mind?
cheers