如何在不修剪的情况下使用 DrawString? [英] How do I use DrawString without trimming?

查看:29
本文介绍了如何在不修剪的情况下使用 DrawString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 DrawString 函数截断整个字符或单词的方式是违反直觉的.显示部分文本清楚地表明缺少某些内容.

I find the way the DrawString function cuts off entire characters or words to be counterintuitive. Showing parts of the text clearly conveys that something is missing.

以下是一些示例:

StringTrimming.None:

StringTrimming.None:

StringTrimming.Character:

StringTrimming.Character:

我想要的:(GIMP 样机)

What I want: (GIMP mockup)

StringTrimming.None 是否与 StringTrimming.Character 相同?在我的情况下,它们的行为似乎完全相同.有什么我可能忽略的地方,或者这是一个已知的功能"?

Is StringTrimming.None the same as StringTrimming.Character? They seem to behave exactly alike in my case. Is there something I could have overlooked or is this a known "feature"?

根据文档 StringTrimming.None指定不修剪."

According to the docs StringTrimming.None "Specifies no trimming."

这个站点 用 Ja​​va 创建的例子甚至显示无"修剪比字符"更多的字符.

This site with examples created with Java even show "None" to trim more characters than "Character".

有没有其他技巧可以达到这种效果?

Are there other tricks to get this effect?

注意:我不想显示..."或类似内容.我觉得这很浪费空间,但这可能是针对 UX 的讨论.

Note: I do not want to display "…" or similar. I find this to be a waste of space but that is probably a discussion for UX.

推荐答案

文本看起来可能被修剪了,因为它实际上隐藏在下一行.在对 Graphics.DrawString 的调用中,通过传递 来禁用包装StringFormat 对象,其 FormatFlags 属性设置为 NoWrap:

It's possible that the text appears to be trimmed because it's actually wrapping invisibly onto the next line. In the call to Graphics.DrawString, disable wrapping by passing a StringFormat object whose FormatFlags property is set to NoWrap:

StringFormat format =
    new StringFormat
    {
        FormatFlags = StringFormatFlags.NoWrap,
        Trimming = StringTrimming.None
    };
g.DrawString(s, font, brush, rect, format);

这篇关于如何在不修剪的情况下使用 DrawString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆