StringFormat flags : 显示整行

发布于 2024-08-17 09:32:46 字数 589 浏览 3 评论 0原文

StringFormat 标志允许在矩形中以不同的方式表示字符串。

在此示例中使用了 string_format.FormatFlags = StringFormatFlags.NoClip 一:

alt text

问题

txt = "The quick brown fox jumps over the lazy dog."

我可以将此文本完全表示为单行(非剪辑且居中)。

我的意思是,我使用默认矩形,但不知道文本的长度是多少,但我知道文本中心应该在哪里。

the StringFormat flags permits to differently represent a string in a rectangle.

in this example was used string_format.FormatFlags = StringFormatFlags.NoClip one:

alt text

Question

having

txt = "The quick brown fox jumps over the lazy dog."

can I represent this text entirely as a single line (non-clipped and centered).

I mean, I use a default rectangle without knowing what will be the length of the text, but i know where should be the text center.

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

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

发布评论

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

评论(1

甜心小果奶 2024-08-24 09:32:46

如果我理解你的问题,我认为 StringFormat.Trimming 属性是实现这种情况的魔力:

StringFormat format = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap);
format.Alignment = StringAlignment.Center;
format.Trimming = StringTrimming.None;
e.Graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, rect, format);

I think the StringFormat.Trimming property is the magic to make this occur, if I understood your question:

StringFormat format = new StringFormat(StringFormatFlags.NoClip | StringFormatFlags.NoWrap);
format.Alignment = StringAlignment.Center;
format.Trimming = StringTrimming.None;
e.Graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, rect, format);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文