VB-NET How to give a new location to a control? , with a variable value

Asked

Viewed 31 times

1

Eaê Personal.

I have this code to define a New Point for a Picturebox, but when running it does not work,...

Dim VarPbx As String = "PictureBox" & "2" 
Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)    
Dim ValorLocation As String = "324, 212"

pbx.Location = New Point(ValorLocation)

Did they find out? I’m a real lay person

I’ve tried other type of variables for(Valorlocation) but he of the expected error in some of the numbers, the right is the value to be Decimal right? Thank you for opening this post.

1 answer

1


It’s simple: you’re passing a String (string) as an argument to build a new Point, and the correct construction is (int, int).

Take the example:

Dim VarPbx As String = "PictureBox" & "2"

Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)

Dim ValorLocationX As Integer = 324
Dim ValorLocationY As Integer = 212

pbx.Location = New Point(ValorLocationX, ValorLocationY)

Besides, you don’t need it to call a member by his name:

Dim VarPbx As String = "PictureBox" & "2"

Dim pbx As PictureBox = CType(Me.Controls.Find(VarPbx, True).FirstOrDefault, PictureBox)

You can simplify with:

Dim VarPbx As PictureBox = Me.PictureBox2

Give a read on instructions, parameters and types of data. =)

  • 1

    Thanks, is that in this part: Dim Varpbx As String = "Picturebox" & "2" this value two is in vdd here a variable that will change to change other Picturebox s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.