简体   繁体   English

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

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

I need to change the location property of label1 from (50, 50) to (50, 70) when Button1 is clicked. 单击Button1时,我需要将label1的位置属性从(50,50)更改为(50,70)。 This should be easy, but I can't get it to work. 这应该很容易,但是我无法使其正常工作。

您也可以这样操作:

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

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”(值类型)。

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. 是的,只需复制并粘贴。

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

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