AutoEllipsis=true affects the vertical positioning of the text

I have a label with AutoEllipsis = true and TextAlign = ContentAlignment.MiddleLeft . When I enter a text that is not extending the label width, the text is vertically aligned to the middle of the label.

However, when the text extends the label width the text is not aligned to the middle, but top aligned instead.

Why is it behaving this way, and is there a way to keep the text vertically center aligned?


I see it. This looks like a limitation in the underlying winapi, DrawTextEx(). Which doesn't get a lot of help from the Label class, it doesn't turn on the DT_SINGLELINE option (aka TextFormatFlags.SingleLine) since it is capable of rendering multiple lines. DrawTextEx() documents that this is required to get vertically centered text (DT_VCENTER). So the real bug is that it shouldn't be centered at all :) Do note that you do get centered text when you grow the label vertically.

The simplest way to work around it is by setting the label's UseCompatibleTextRendering property to True.

链接地址: http://www.djcxy.com/p/28260.html

上一篇: 将UILabel文字对齐左下角

下一篇: AutoEllipsis = true会影响文本的垂直位置