I posted a question similar to this earlier, however, after thinking about it and testing the answers, I believe I misinterpreted the answers and the answerer(s) misinterpreted me. The original question is here. I think people believed that I just wanted to highlight strings, I didn't state my exact purpose. So, I will now:
What I've been trying to do lately is create a 100% from scratch text box in C++ CLR using GDI+. I've gotten to the challange of placing the caret when the user clicks in the textbox. Doing simple math (Where they clicked divided by line width) I can figure out which line they clicked. But in order to get the character clicked, I need (unless there are better ways) to compare the bounding rectangles of all the characters in the line and place the caret before the one the mouse fits into. In order to do this, I need to get the exact bounds of each individual character, not an entire string.
I've already tried a few things, none of which seemed to work:
- Graphics::MeasureString is not recommended by anyone, nor does it give what I want
- TextRenderer::MeasureText is more accurate, but for this not accurate enough
- Graphics::MeasureCharacterRanges has a 32 character cap, and I'm expecting lines to be over 32 characters long in some cases
I believe I can't use these methods, unless there are ways around their limitations. I hope I made my problem and expected solution a lot more clear than I previously did.