没有 Win32 API 调用的 C# 路径省略号

发布于 2024-08-26 14:32:00 字数 272 浏览 4 评论 0原文

我想缩短一条很长的路径,以便使用省略号字符在表单上显示。

我知道有 PathCompactPathEx Win32 API 调用,但我知道有一个内置的 .NET 等效项。我以前用过它,但现在找不到了。有什么提示吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇俏 2024-09-02 14:32:02

从(至少)版本 3.5 开始,在 .Net 版本中使用 ModifyString 标志会暴露出丑陋且 此处讨论的潜在危险错误

汉斯·帕桑特找到了 正确的方法在这里执行此操作

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.

瑾兮 2024-09-02 14:32:00

你自己的链接有

替代托管 API:
System.Windows.Forms.TextRenderer.MeasureText(String, Font, Size, TextFormatFlags.ModifyString | TextFormatFlags.PathEllipsis);

在底部。这就是您要找的吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文