Last post Sep 09, 2007 07:24 AM by skuggbo
Sep 08, 2007 08:54 AM|skuggbo|LINK
We are running a project where we need to draw an image that are exactly as big as the largest text string is. One text string is one row.
A text string can be any font family, size and font style.
We found a solution to measure a text string exactly, by draw it on a temporary bitmap and loop through it and find the first color that differs from the background. So we know the size of the text strings. The problem occurs when we are going to draw it
by using DrawString method. It seems that the method adds some pixles before the string (depending on the size of the string and font family). How do I know how much this space is?
Sep 08, 2007 12:43 PM|vcsjones|LINK
MUCH better way to do this is to use the MeasureString method on the Graphics class:
This will give you the diamensions of a string, without the "Temp" image, and it will be a
lot better for performance than what you are using.
Sep 09, 2007 07:24 AM|skuggbo|LINK
The reason for why I'm doing this is because MeasureString is not good enough. Everyone that have been working with MeasureString knows this problem.
Try yourself to draw 3 rows with the same text in one small and two larger fonts, then you will see that they will not start exactly at the same left position. The larger size will have a larger space.
Thank you anyway for your reply.