Windows Develop Bookmark and Share   
 index > Windows Forms General > More RichText Measuring
 

More RichText Measuring

I found a small flaw in my logic for measuring the length of RichText strings (see this post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1628727&SiteID=1).

The problem is that I've discovered that in the case of a 1 character string, EM_FORMATRANGE always returns 2 indicating that the character fits (it should return string length + 1 if everything fits) even if the width of the space is 0! It seems that for the case of a 1 character string it will always calculate that the character fits even if it's cut in half (or there's no space at all). This leaves me with the problem of how to calculate the width needed to fit a single rich text character. Any ideas?

wjousts  Monday, July 16, 2007 7:18 PM

Hi,there is a bug which is known by microsoft.

http://support.microsoft.com/kb/814318/en-us

When the Start parameter is equal to the length of the string, the Find method of the RichTextBox control does not raise an exception, even though the string positional count starts with zero. For example, if the string is "abcde", string position zero indicates that the string starts from "a". When the Start parameter is set to the string length, RichTextBox searches the string from the zero position, and then returns the first instance position of the search string.

This bug occurs because the Find method of the RichTextBox control does not handle the upper boundary condition (RichTextBox.Text.Length).

With Regards

Gavin Jin - MSFT  Friday, July 20, 2007 1:45 AM
Thanks for the reply, but I don't see how it relates to my problem. I'm trying to measure how many pixels a rich text string will need to fit on the screen. I'm using SendMessage with EM_FORMATRANGE which should tell me how many characters fit in a given rectangular area, then I change the size until I find the point where not all the characters fit anymore and this gives me a crude measure of how much space I need. The problem is that, for a one character string, EM_FORMATRANGE always claims the character fits, even if it doesn't.
wjousts  Friday, July 20, 2007 12:33 PM

You can use google to search for other answers

Custom Search

More Threads

• Help Needed
• Hard Disk Drives Count
• Performance problem
• Application dissappears
• OwnerDrawFixed listBox problem
• Customize built in components, how?
• tooltip shows wrong message
• Thread not abort when the form closes
• How to create an extended form base class?
• Layered windows corrupting OpenGl ones