Hi m@,
>Bo, that's unbelievable!!! I really thought it might not be possible, but this works beautifully.
>
>Thank you!!
Your welcome.
>Nothing to do with the code that you provided, but I have noticed that GDI's MeasureString() isn't always 100% accurate when I use it to redraw the editbox based on the text value. It's WAY better than using the fontmetric, but are you aware of any tricks to making it closer to perfect?
When you say "GDI's", I assume you are talking about GDIPlus. GDI is the old graphics engine and GDIPlus is the new, with the MeasureString function.
The problem is that the EditBox (as well as most screen drawing of text and controls) are using "GDI", which is integer based, whereas "GDIPlus" is float based. So the differences you are seing are basically rounding errors. The more text you have and the more lines it wraps, the more of a difference you will see between the two.
Like I hinted in my last post, if you want it dead on accurate, you have to use the same graphics engine to do the calcultations.
BTW, FoxPro's TXTWIDTH function uses GDI. You just have to translate the font information to make it work right. It is still very difficult to predict line wrap though, that is what makes the function I sent you more accurate for what you are trying to accomplish.