Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,094 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,596 people online right now. Registration is fast and FREE... Join Now!




Determining height of text in RichTextBox with complex formatting

 
Reply to this topicStart new topic

Determining height of text in RichTextBox with complex formatting

Ryujin
30 Oct, 2007 - 03:13 AM
Post #1

New D.I.C Head
*

Joined: 30 Oct, 2007
Posts: 2


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Ryujin
RE: Determining Height Of Text In RichTextBox With Complex Formatting
30 Oct, 2007 - 09:53 AM
Post #2

New D.I.C Head
*

Joined: 30 Oct, 2007
Posts: 2


My Contributions
... I'm a moron. I think I might have overlooked an easy solution. I'll post if it works.
User is offlineProfile CardPM
+Quote Post

stankovski
RE: Determining Height Of Text In RichTextBox With Complex Formatting
21 Nov, 2007 - 06:58 AM
Post #3

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 1


My Contributions
Where you able to find the solution?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:26PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month