简体   繁体   English

标签文字从右到左更新

[英]label text update from right to left side

how it is possible to set label string in my case with several updated values: 在我的情况下,如何使用几个更新的值设置标签字符串:

 label1.Text = (num1 + "." + num2 + "." + num3);

Not in the usual way: 并非以通常的方式:

                        123.8576.87687
                        17.87.1299987
                        9881.0.87
                        765443345600.08776.877667
                        09.8.112

but with update from right to left side if I want locate it near to the right border of the form, and if this numbers is a sequence of updated values from given string for one label, each time string with different length: 但是如果我想将其从表单的右边界附近移到右侧,则从右向左进行更新,并且如果该数字是一个标签的给定字符串的一系列更新值,则每个时间字符串的长度都不同:

           123.8576.87687
            17.87.1299987
                9881.0.87
765443345600.08776.877667
                 09.8.112

of some this way: 这种方式:

           87687.8576.123
            1299987.87.17
                87.0.9881
877667.08776.765443345600
                 112.8.09

to locate it in the corner of the form: 在表格的一角找到它:

在此处输入图片说明

Try setting AutoSize to false and set TextAlign as MiddleRight 尝试将AutoSize设置为false并将TextAlign设置为MiddleRight

label1.AutoSize = false;
label1.TextAlign = ContentAlignment.MiddleRight;

您可以如下定义label textAlign属性:

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

Basically, two things that you should make: 基本上,您应该做两件事:

Set the TextAlign property like this: 像这样设置TextAlign属性:

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

Then set the AutoSize property to false: 然后将AutoSize属性设置为false:

this.label1.AutoSize = false;

Make sure the size of the label is big enough to fit all numbers and that is it. 确保标签的大小足够大以适合所有数字。 在此处输入图片说明

I have a theory that the problem with label text and autosize is that autosize makes the size of the text field exactly as big as necessary for the text to it. 我有一个理论,标签文本和自动调整大小的问题在于,自动调整大小会使文本字段的大小恰好等于文本所需要的大小。 Therfore it does not matter where you put contentalignment. 因此,将contentalignment放在何处都没有关系。 The field changes size according to space needed for containing the text. 该字段根据包含文本所需的空间来更改大小。 Location is not changed. 位置不变。 So, to workaround this you have to manipulate the position of the label. 因此,要解决此问题,您必须操纵标签的位置。

labData.Text = "text"
int labDataRight = lblData.Right;
lblData.Text = "A slightly longer text"; // Autosize will resize the label
lblData.Left = labDataRight - lblData.With;

I haven't tested this profoundly, it might be that the label position will drift after many changes. 我尚未对此进行深入测试,可能是标签位置在进行许多更改后会发生漂移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM