AutoEllipsis=true affects the vertical positioning of the text

喜你入骨 提交于 2019-12-10 13:04:59

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/24447344/autoellipsis-true-affects-the-vertical-positioning-of-the-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!