Hello is it possible to have a single line label show an ellipses in the event that text is too long? The Listbox control does this automatically when text within a cell is too large to show. Thanks!
AFAIK, not automatically. You’ll have to calculate the text length and add the ellipsis in code.
Or you can use a Canvas and graphics.drawstring <string>, x, y, width, true
But be warned doing this in too many controls is slow.
Here’s class extension that I put together to reuse in a few projects that does what you’re looking for:
[code]Public Sub TruncateText(extends aLabel as Label, assigns aString as String)
dim p as new Picture(1,1)
p.Graphics.TextSize = aLabel.TextSize
p.Graphics.TextFont = aLabel.TextFont
p.Graphics.Bold = aLabel.Bold
p.Graphics.Italic = aLabel.Italic
dim stringWidth as integer = p.Graphics.StringWidth(aString)
if stringWidth <= aLabel.Width then
aLabel.Text = aString
return
end
for i as integer = aString.Len downto 0
if p.Graphics.StringWidth(Left(aString,i) + “…”) <= aLabel.Width then
aLabel.Text = Left(aString,i) + “…”
return
end
next
aLabel.Text = “”
End Sub
[/code]
Thanks Jared, that worked perfectly!