使用 VB.net 以编程方式更改 Windows 窗体上控件的位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/535087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:03:25  来源:igfitidea点击:

Changing the location of a control on a windows form programatically using VB.net?

vb.net

提问by user39035

I need to change the location property of label1 from (50, 50) to (50, 70) when Button1 is clicked. This should be easy, but I can't get it to work.

单击 Button1 时,我需要将 label1 的位置属性从 (50, 50) 更改为 (50, 70)。这应该很容易,但我无法让它工作。

回答by msimons

You can also do it this way:

你也可以这样做:

label1.Location = new Point(x,y);

回答by Matt Hamilton

What are you trying? I find the easiest thing to do is set the Top and Left properties individually:

你在尝试什么?我发现最简单的方法是单独设置 Top 和 Left 属性:

label1.Left = 50;
label1.Top = 70;

Setting Location.X and Location.Y will probably result in a compile-time error, because Location is of type "Point", a value type.

设置 Location.X 和 Location.Y 可能会导致编译时错误,因为 Location 是“Point”类型,一种值类型。

回答by Minion

Just do like this.

就这样做吧。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Label1.Location = New Point(50, 70)
End Sub

Yes just copy & paste.

是的,只需复制和粘贴。