问题描述
根据我对文档,当使用TextFormatFlags.EndEllipsis
时,应将文本修剪为适合显示矩形的内部,并用省略号代替:
According to my understanding of the documentation, when using TextFormatFlags.EndEllipsis
the text should be trimmed to fit inside the display rectangle and replaced with an ellipsis:
使用TextFormatFlags.WordEllipsis
时,应将文本修剪为适合显示矩形的最后一个单词,并添加省略号:
When using TextFormatFlags.WordEllipsis
, the text should be trimmed to the last word that fits inside the display rectangle, and add an ellipsis:
但是,我似乎找不到两者之间的任何区别.
However, I can't seem to find any difference between these two.
这是我的测试控件的代码:
Here is my test control's code:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.Text = "This it my text. It's long enough to get cut in display.";
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var flags = (this.IsWordEllipsis) ? TextFormatFlags.WordEllipsis : TextFormatFlags.EndEllipsis;
TextRenderer.DrawText(e.Graphics, this.Text, this.Font, e.ClipRectangle, this.ForeColor, flags);
}
private bool _IsWordEllipsis;
public bool IsWordEllipsis
{
get { return _IsWordEllipsis; }
set { _IsWordEllipsis = value; this.Invalidate(); }
}
}
无论我将IsWordEllipsis
属性设置为什么值-文本始终呈现为This it my text. It's long eno...
.
No matter what value I set the IsWordEllipsis
property - the text is always rendered asThis it my text. It's long eno...
.
是否不应该使用WordEllipsis
标志将显示的字符串修剪为最后一个完整的单词?
(This it my text. It's long ...
)
Shouldn't using the WordEllipsis
flag trim the displayed string to the last complete word?
(This it my text. It's long ...
)
推荐答案
内部TextRenderer.DrawText
调用 DrawText 函数
相应的标志是:
DT_END_ELLIPSIS 对于显示的文本,如果字符串的末尾没有 适合矩形,它被截断并添加了椭圆.如果一个 不在字符串末尾的单词超出了 矩形,它被截断而没有椭圆.
DT_END_ELLIPSIS For displayed text, if the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses.
我已经以与您相同的方式解释了WordEllipsis
的.NET文档,但是上面的句子可能更好地说明了该选项的作用.
I have interpreted .NET documentation for WordEllipsis
same way as you, but above sentence probably better explains what this option is supposed to do.
如果仍然不清楚,请看一下这个简单的示例,该示例尝试呈现var quote = "Not every thing that\n can be counted counts,\n and not everything that\n counts can be counted.";
In case it is still unclear take a look at this simple example, which tries to render var quote = "Not every thing that\n can be counted counts,\n and not everything that\n counts can be counted.";
这篇关于TextFormatFlags枚举中的EndEllipsis和WordEllipsis有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!