TextFormatFlags枚举中的EndEllipsis和WordEllipsis有什么区别? [英] What's the Difference between EndEllipsis and WordEllipsis in TextFormatFlags enum?

查看:350
本文介绍了TextFormatFlags枚举中的EndEllipsis和WordEllipsis有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我对

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:

EndEllipsis  |  删除修剪的线的末端,并将其替换为省略号.

EndEllipsis   |   Removes the end of trimmed lines, and replaces them 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:

WordEllipsis  |  将行修剪到最接近的单词,并在修剪的行的末尾放置省略号.

WordEllipsis   |   Trims the line to the nearest word and an ellipsis is placed at the end of a trimmed line.

但是,我似乎找不到两者之间的任何区别.

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 as
This 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调用相应的标志是:

DT_WORD_ELLIPSIS :截断与 矩形并添加椭圆.

DT_WORD_ELLIPSIS: Truncates any word that does not fit in the rectangle and adds ellipses.

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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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