Label painting issue
Posted on 2004-11-16
I'm using custom painting to display a string in a label with the StringTrimming set to display shortened paths when the string is too long. For example, instead of seeing "C:\Windows\Syst" I would see "C:\...\System32".
The code I have is like this:
Dim sf As New StringFormat(StringFormatFlags.LineLimit)
sf.Trimming = StringTrimming.EllipsisPath
g.DrawString(.Text, .Font, foreBrush, RectangleF.op_Implicit(e.ClipRectangle), sf)
This works fine, but I noticed something odd about the way the label is drawn. When the form is on top everything is fine. But if I drag another window around, the string is only drawn to the edge of the label that is visible.
This is most definitely because of the ClipRectangle being changed to reflect the visible area. I tried using the label's bounds instead, but then it wrapped the text across two lines instead of only drawing a single line. I've tried using StringFormatFlags.NoWrap in addition to LineLimit, but nothing seems to be forcing the text onto one line. What am I doing wrong?