开发者

C# Path Ellipsis without Win32 API call

开发者 https://www.devze.com 2022-12-24 03:35 出处:网络
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 c开发者_如何转开发all, but I know there is a built-i

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 c开发者_如何转开发all, but I know there is a built-in .NET equivalent. I have used it previously, but cannot find it any more. Any hints, please?


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?


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

Hans Passant found the correct way to do this here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号