Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding ellipsis (...) to content that's too big for a textbox/editbox

Status
Not open for further replies.

awaresoft

Programmer
Feb 16, 2002
373
0
0
DE
I'm in the process of trying to add ellipsis (...) to the content of certain textboxes, editboxes, and labels when the content of these controls is greater than these control's display area. In other words, I plan on trimming the value displayed in these controls so that the largest amount of content can be displayed in the control followed by "...".

Apparently VFP 9 can do this to textbox controls displayed in a grid - but I'm looking for a solution that allows me to do this with regular textboxes, editboxes, and labels.

I've looked at DisplayPath() but this function assumes a fixed pitch font. I'm currently in the process of looking at Fontmetric() as a way to calculate the max number of chars I can display in a given width, but can't seem to think of a way to apply this function when a multiline, word-wrapped value is displayed in a textbox, editbox, or label.

Any suggestions?

Malcolm
 
Hi Malcolm,

Well, as I said in your other thread, the best way is setting a label caption to the text for determining the width and height it really takes. Fontmetric will also only give you information about a normal/middle length and will fail if a text as many "i" or spaces or "W" in it.

Bye, Olaf.
 
Olaf,

As it turns out, the solution for the width of one line text strings is simple, use a form's TextWidth() method. In my case I create a hidden, throwaway form, set its font characteristics to match the font I'm using, call its TextWidth() method, and then destroy the form. Works great!

Now if I could only find a way to solve that pesky problem of measuring the width of a word wrapped text string. (A form's TextHeight() method does not appear to add value here)

Malcolm
 
Closing this thread out - DrawText and CreateFont can be used to accurately measure the width of a single line of text displayed in a VFP textbox or caption. A simpler solution is to use a form's TextWidth method (setting and restoring the form's font properties to match the string of text you want to measure).

Unfortunately, it appears(?) that VFP's editbox uses a word wrapping technique that's slightly different than the technique used by DrawText and CreateFont, and thus using these functions to measure multi-line text height or to generate ellipsis terminated multi-line strings is useless.

For anyone following in my footsteps, please see my posts in the VFP General forum concerning "Measuring height of a wordwrapped string" as well as similar posts under the topic of "Autosizing Editbox" on the Wiki, Universalthread, ProfoxTech, and News2News.com.

Malcolm
 
awaresoft,

how VFP 9 can do this to textbox controls displayed in a grid?

Michael Kopljan
 
Michael,
Actually VFP 9.0 doesn't give elipses, it provides a "tooltip" showing all the data in the textbox when the column width doesn't allow it to be seen.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top