C# Path Ellipsis without Win32 API call

两盒软妹~` 提交于 2019-12-01 06:58:45

问题


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?


回答1:


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?




回答2:


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.



来源:https://stackoverflow.com/questions/2529436/c-sharp-path-ellipsis-without-win32-api-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!