[archived content]
Dfl /

Showing a file path in a label

Some file paths take up too much space so you want to trim out the middle, here's a control you can use to do this:

class PathLabel: Label
{
        protected override void onPaint(PaintEventArgs ea)
        {
                scope tfmt = new TextFormat(TextFormatFlags.NO_PREFIX
                | TextFormatFlags.SINGLE_LINE | TextFormatFlags.NO_CLIP);
                tfmt.trimming = TextTrimming.ELLIPSIS_PATH;
                tfmt.alignment = TextAlignment.LEFT | TextAlignment.MIDDLE;

                ea.graphics.drawText(text, font, foreColor,
                Rect(2, 0, clientSize.width - 4,
                clientSize.height), tfmt);

                paint(this, ea);
        }
}

Use it just like a regular Label. Here's a screenshot:

You can even use this in Entice Designer by adding a regular Label to your form, right-clicking it, going into the Properties, and changing the type to PathLabel.

Page last modified on March 31, 2008, at 07:57 PM