在的WinForms右对齐的标签

在的WinForms右对齐的标签

本文介绍了在的WinForms右对齐的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最明显的方法来右对齐标签中的WinForms不工作:设置锚顶/底权与textAlign设置为TopRight。如果文本改变标签的左侧坐标保持不变,而不是正确的坐标(其中,人们可能会认为,是一个错误)。

The most obvious way to right-align a Label in WinForms doesn't work: setting anchor to Top/Bottom Right and TextAlign to TopRight. If the text changes the label's Left coordinate remains unchanged instead of the Right coordinate (which, one might argue, is a bug).

为此,我一直使用全角的TableLayoutPanel 右对齐的标签。然而,这并不总是很方便,这取决于所讨论的布局...

For this reason I've always used a full-width TableLayoutPanel for right-aligned labels. However this is not always very convenient, depending on the layout in question...

所以,我不知道是否有任何其他的方法来保持一个标签右对齐的,从来没有发生在我的WinForms?

So, I wonder if there are any other ways to keep a Label right-aligned in WinForms that never occurred to me?

推荐答案

一个简单的办法是禁用自动调整大小(设置为)及以上尺寸的这么有剩余的空间。

One simple option is to disable AutoSize (set to false) and over-size it so there is spare space.

另外,或者使用码头,而不是仅仅,虽然这有不同的含义,所以你可能需要把它放在一个面板或类似的)研究。最终,这就像第一次 - 超过施胶摆在​​首位它;所以也许是第一个选择是简单的。

Alternatively, perhaps use Dock instead of just Anchor, although this has a different meaning, so you may need to put it in a Panel or similar). Ultimately this works like the first - by over-sizing it in the first place; so perhaps the first option is simpler.

这篇关于在的WinForms右对齐的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:49