如何在Windows窗体中将标签相对于另一个标签的位置对齐? [英] How to align a label relative to another label's position in a Windows form?
问题描述
大家好,
我是Visual Studio的新手,所以我很抱歉我可能有一些简单的问题。我想将标签的位置相对于另一个标签的大小(宽度)对齐。我将在左侧有一个标签,其中包含一串不同的
长度的字符串。无论字符串有多长以及标签有多宽,我都希望第二个标签的左边缘始终连接到第一个标签的右边缘(或者两者之间可能是一个恒定的偏移)。有什么方法可以做到这一点吗?我很感激
任何帮助。谢谢!
I'm very new to Visual Studio, so I'm sorry for the probably simple questions I may have. I'd like to align a label's position in a form relative to the size (width) of another label. I will have one label on the left that will contain a string of varying length. No matter how long that string is and how wide that label gets, I want the left edge of the second label to always be connected to the right edge of the first label (or perhaps a constant offset between the two). Is there any way I can do this? I appreciate any help. Thanks!
推荐答案
处理 SizeChanged 即使是第一个标签。 (转到表单设计器,选择标签,转到"属性"窗口等)。像这个处理程序一样设置
左属性:
Handle the SizeChanged even of the first label. (Go to form designer, select the label, go to Properties window, etc.). Set the Left property like in this handler:
private
void label1_SizeChanged(
object sender,
EventArgs e)
{
label2.Left = label1.Right + 10;
label2.Left = label1.Right + 10;
}
其中10是偏移量。
也可以在Visual Basic中完成。
这篇关于如何在Windows窗体中将标签相对于另一个标签的位置对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!