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

前端 未结 3 1597
不知归路
不知归路 2020-12-20 15:30

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.

相关标签:
3条回答
  • 2020-12-20 15:47

    You can also do it this way:

    label1.Location = new Point(x,y);
    
    0 讨论(0)
  • 2020-12-20 15:48

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

    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.

    0 讨论(0)
  • 2020-12-20 15:48

    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.

    0 讨论(0)
提交回复
热议问题