gpt4 book ai didi

c# - 标签中的路径显示

转载 作者:太空狗 更新时间:2023-10-29 20:56:05 24 4
gpt4 key购买 nike

在 .NET 中是否有任何自动修剪路径字符串的方法?

例如:

C:\Documents and Settings\nick\My Documents\Tests\demo data\demo data.emx

成为

C:\Documents...\demo data.emx

如果将它内置到 Label 类中会特别酷,我似乎记得它是——虽然找不到它!

最佳答案

TextRenderer.DrawTextTextFormatFlags.PathEllipsis 标志一起使用

void label_Paint(object sender, PaintEventArgs e)
{
Label label = (Label)sender;
TextRenderer.DrawText(e.Graphics, label.Text, label.Font, label.ClientRectangle, label.ForeColor, TextFormatFlags.PathEllipsis);
}

Your code is 95% there. The only problem is that the trimmed text is drawn on top of the text which is already on the label.

是的,谢谢,我知道了。我的目的只是为了演示 DrawText 方法的使用。我不知道你是想为每个标签手动创建事件,还是只是重写继承标签中的 OnPaint() 方法。感谢您分享您的最终解决方案。

关于c# - 标签中的路径显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com