This new feature is definitely one that many users had been looking forward to for ages. It returns a rectangle that is the bounding box of a character.
How to use it?
Syntax:
First you have to get the position of a character in a string. e.g. "FLASH", then "F" corresponds to 0, "L" corresponds to 1, etc. This is the parameter charIndex. You will get back the rectangle that bound the character at the location charIndex.
Read livedocs for more details.
Here's an example. Search for sth and the match will be highlighted. The yellow highlighting patch is drawn by the drawing API. Get the source here.
However there are some limitations or skills in using this new method....
Limitations
To solve the first problem, you can get the rectangle of the first and the last character of the string you want, then you can calculate the length of the string. So the code will be sth like this:
For the 2nd problem, the rectangle has about 2px of deviation from the exact location (i.e. it cannot cover the whole string completely). It would not be neat to have a little part of the string not covered by the yellow rectangle in the above example. I think this is probably due to the 2 px gutters of textfield.
Therefore to correct this in my example, I add 2 to the x,y coordinate of rect3 (as follows).