views:

227

answers:

2

I have a long path I'd like to shorten for displaying on a form using the ellipsis character(s?).

I know there is the PathCompactPathEx Win32 API call, but I know there is a built-in .NET equivalent. I have used it previously, but cannot find it any more. Any hints, please?

+3  A: 

Your own link has

Alternative Managed API: System.Windows.Forms.TextRenderer.MeasureText(String, Font, Size, TextFormatFlags.ModifyString | TextFormatFlags.PathEllipsis);

at the bottom. Is that what you are looking for?

Logan Capaldo
You were faster. `TextRenderer.DrawText()` to render it accordingly.
Benjamin Podszun
Errr, yes. How embarrassing. Thanks :)
Rezzie
+2  A: 

Using the ModifyString flag in versions of .Net since (at least) version 3.5 exposes an ugly and potentially dangerous bug discussed here: http://tinyurl.com/y47jxgw

Hans Passant found the correct way to do this here: http://tinyurl.com/y6vuvrh

casterle